Batch rounding a number

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

    Here is a native batch/jscript hybrid posted recently that will
    return a MB figure, for a byte figure given as %1 (and not limited to 2GB figures as batch math is)

    It does not round up or round down the partial megabyte after the decimal point, it just removes it.

    @if (@CodeSection == @Batch) @then
    
    @echo off
    set JScall=Cscript //nologo //E:JScript "%~F0"
    for /f "delims=." %%a in ('%JScall% "%~1/1024/1024"') do set "size=%%a"
    echo %size%
    goto :EOF
    
    @end
    WScript.Echo(eval(WScript.Arguments.Unnamed.Item(0)));
    

提交回复
热议问题