Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Numeric variables comparison

Nov
33
0
Hi guys, this cmd batch works fine if it runs without TCC:

Code:
@ECHO OFF

SET "var_a=8.5"
SET "var_b=8.4.9"

IF %var_a% LSS %var_b% (
ECHO NOT CORRECT)

But If I run it with TCC the result is not correct. Why?
I would like to find a solution compatible for both systems (cmd batch and TCC)

Thank you!!
 
TCC and CMD do the same thing here. The ECHO is not executed.

TCC:

Code:
v:\> *ver & type var_a.btm & var_a.btm

TCC  28.02.18 x64   Windows 10 [Version 10.0.19045.2728]
@ECHO OFF

SET "var_a=8.5"
SET "var_b=8.4.9"

IF %var_a% LSS %var_b% (
ECHO NOT CORRECT)

v:\>

CMD:

Code:
v:\> ver & type var_a.bat & var_a.bat

Microsoft Windows [Version 10.0.19045.2728]
@ECHO OFF

SET "var_a=8.5"
SET "var_b=8.4.9"

IF %var_a% LSS %var_b% (
ECHO NOT CORRECT)

v:\>
 
It looks like TCC only does a numeric comparison if both values are numeric. Seems reasonable enough to me. The @NUMERIC function may be of use here.
 
It looks like TCC only does a numeric comparison if both values are numeric. Seems reasonable enough to me. The @NUMERIC function may be of use here.
Which setting do you suggest to modify in TCMD.ini? Because also without TCMD.ini the result is the same: NOT CORRECT.

Thank you!!
 
This code;
Code:
@ECHO OFF

SET var_a=8.5
SET var_b=8.4.9

echo var_a: %var_a%
echo var_b: %var_b%

echo Before Evaluation

IF %var_a% LSS %var_b% call :Evaluate

echo After Evaluation

goto :end

:Evaluate
echo var_a is less than var_b
exit /b

:end
...returns...
Code:
R:\>test.cmd
var_a: 8.5
var_b: 8.4.9
Before Evaluation
After Evaluation

This code;
Code:
@ECHO OFF

SET var_b=8.5
SET var_a=8.4.9

echo var_a: %var_a%
echo var_b: %var_b%

echo Before Evaluation

IF %var_a% LSS %var_b% call :Evaluate

echo After Evaluation

goto :end

:Evaluate
echo var_a is less than var_b
exit /b

:end
...returns...
Code:
R:\>test.cmd
var_a: 8.4.9
var_b: 8.5
Before Evaluation
var_a is less than var_b
After Evaluation

Only difference between the two is the exchange of var_a and var_b.

Works the same in both TCC and CMD.

Joe
_x64: 1
_admin: 1
_elevated: 1

TCC 29.00.17 x64 Windows 10 [Version 10.0.19044.2728]
 
It's the DecimalChar/ThousandsChar settings. If I change mine (both Auto) to DecimalChar=, and ThousandsChar=. TCC echoes "NOT CORRECT".

It seems the test for numeric could handle the ThousandthsChar better. Here, with ThousandsChar=Auto (comma I reckon)

Code:
v:\> echo %@numeric[1,2,3]
1
 
Code:
R:\>option //ThousandsChar=.

R:\>option //DecimalChar=,

R:\>test.cmd
var_a: 8.4.9
var_b: 8.5
Before Evaluation
After Evaluation

R:\>option //ThousandsChar=Auto

R:\>option //DecimalChar=Auto

R:\>test.cmd
var_a: 8.4.9
var_b: 8.5
Before Evaluation
var_a is less than var_b
After Evaluation

Good catch @vefatica

Joe
 

Similar threads

Back
Top