Batch rounding a number

后端 未结 5 658
滥情空心
滥情空心 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:43

    It would be better if you showed the script in question, but yes, rounding can be performed. We just have to do the process manually. Here is a routine that will take in the number and a variable for the result.

    :Round  
    setlocal
    for /f "tokens=1,2 delims=." %%A in ("%~1") do set "X=%%~A" & set "Y=%%~B0"
    if %Y:~0,1% geq 5 set /a "X+=1"
    endlocal & set "%~2=%X%"
    exit /b 0
    

    Usage:

    @echo off
    setlocal
    call :Round 12345.6789 Out
    echo %Out%
    endlocal
    exit /b 0
    

提交回复
热议问题