Batch rounding a number

后端 未结 5 648
滥情空心
滥情空心 2021-01-25 21:23

I have a script that calculates disk space in bytes. I have found a way to convert it to megabytes. I have just run it and i got a this: 1867.603187561035. Is there

5条回答
  •  囚心锁ツ
    2021-01-25 21:58

    If you just want get the number before the . :

    @echo off
    
    set $value=1867.703187561035
    
    for /f "tokens=1 delims=." %%a in ('echo %$Value%') do set %$number%=%%a
    
    echo %$Number%
    

    And if you really want to test the second part of the number :

    @echo off
    
    setlocal EnableDelayedExpansion
    set $value=1867.703187561035
    
    for /f "tokens=1,2 delims=." %%a in ('echo %$Value%') do (
    set $Number=%%a
    set $Vtest=%%b
    if "!$Vtest:~0,1!" geq "5" set /a $Number+=1
    )
    
    echo !$Number!
    

提交回复
热议问题