lundi 13 janvier 2020

Batch comparing 2 numbers result wrong output

I am testing something with a batch file to compare 2 numbers if greater, less or equal. I start making this test to find out why my other script that requires a comparison between 2 numbers and did not work properly. During the test I found the issue and I cannot understand why it's happening. I hope you can help me with this one.

Let's say I have 2 variables:

set a=12.5
set b=10.0

if I compare those 2 numbers:

IF %A% GTR %B% (echo A greater than B) ELSE (IF %A% LSS %B% (echo B greater than A) ELSE (echo A equal B))

The output is: A greater than B

I tested multiple numbers with decimals and works just fine, EXCEPT when one number is less than 10 and the other number is higher than 10.

example:

set a=9.9
set b=12.3

IF %A% GTR %B% (echo A greater than B) ELSE (IF %A% LSS %B% (echo B greater than A) ELSE (echo A equal B))

in this case the output is: A greater than B which is wrong.

Anyone can explain me why is this happening and how to fix this?

Thank you.

Aucun commentaire:

Enregistrer un commentaire