1

I am passing 12345678.02 and I wanted to get value after decimal i.e "02" and then i do have the another text file wanted to replace the value.

 <add key="BuildVersion" value="12345678.01" /> 

by.

 <add key="BuildVersion" value="12345678.02" />

I wrote the bellow code but it always gives me Echo is off.

set/p pass="%pass%" 
set "number_to_round=%pass%"
for /f "tokens=1,2 delims=." %%a  in ("%number_to_round%") do (
    set first_part=%%a
    set second_part=%%b
)
set second_part=%second_part:~0,1%
echo %second_part%
if defined second_part if %second_part% GEQ 5 ( 
    set /a rounded=%second_part%+1
) else ( 
    set /a rounded=%second_part%
)
echo %rounded%>newVersionbeafterdecimal.txt
  • Batch has only variable type string (sometimes converted to signed 32 bit integers). There is no float. Also numbers with leading zeores are interpreted as octal. How would adding one hundreds perform rounding? It's unclear to me what you are trying to do. –  Aug 14 '17 at 08:13
  • @LotPings I got the solution set/p pass="%pass%" set "number_to_round=%pass%" for /f "tokens=1,2 delims=." %%a in ("%number_to_round%") do ( set first_part=%%a set second_part=%%b ) set second_part=%second_part:~0,2% echo %second_part% if defined second_part if %second_part% GEQ 5 ( set /a rounded=%first_part%+1 ) else ( set /a rounded=%first_part% ) – Unmesh Ghatbandhe Aug 14 '17 at 08:36
  • 1
    Don't post code in a acomment, **IF** this is different from your question [edit] the question. –  Aug 14 '17 at 09:03
  • Possible duplicate of [Batch- do more advanced calculations](https://stackoverflow.com/questions/17235611/batch-do-more-advanced-calculations) –  Aug 21 '17 at 13:47

1 Answers1

0

If the fractional part always has 2 digits it's much easier to:

  1. simply remove the decimal point
  2. increment by one and
  3. reinsert the decimal point.

@Echo off
set/p "pass=Version number %pass%"
If "%pass:~-3,1%" neq "." (Echo Invalid version number %pass% &Pause&Goto :Eof)
Echo pass=%pass%
Set /A pass=%pass:.=% + 1
Echo pass=%pass%
Set "pass=%pass:~0,-2%.%pass:~-2%"
Echo pass=%pass%

echo %pass%>newVersion.txt

The echo lines are inserted to show what's happing and may be removed.

Sample run:

>  SO_45668510.cmd
Version number 12345678.01
pass=12345678.01
pass=1234567802
pass=12345678.02