How to truncate a number in a batch file
Posted on 2005-03-31
I have a number with a 3 digits after the decimal point. For example, I want to be able to truncate 10000.000 to just display 10000. For some reason, I can only seem to do this with numbers smaller than 10000. I have been doing it this way:
set /n = 10000.999
set a/ n = %n:~0,-4%
If the number is 5 digits or more with 3 decimal places(xxxxx.xxx), it will not work. In other words, if the number is over 10000 and has 3 decimal digits, it ignores the decimal and truncates the 10000 4 digits to the number 1.
I am actually doing this in a for loop:
for /f "tokens=1,2,3,8 delims=\ " %%a in (myfile.txt) do (...
and in this loop I tried to truncate the %%a variable. I tried set /a %%a = %%a:~0,-4 but that did not work. What I am trying to do now is this
set /a n=%%a
set /a %n:~0,-4%
This works until I get to a number that is higher than 10000.000
I would appreciate any help.