标题: 如何用cmd做四舍五入运算?
[打印本页]
作者: peterdocter
时间: 2007-4-1 12:42
标题: 如何用cmd做四舍五入运算?
可以做到吗?
作者: bjsh
时间: 2007-4-1 22:55
可以
作者: bjsh
时间: 2007-4-1 22:55
把你的要求再具体一下;
比如举个例子上来;试试帮你写写代码
作者: bjsh
时间: 2007-4-2 02:40
试试这个吧
- @echo off &SetLocal EnableDelayedExpansion
- set /p x=请输入被除数:
- set /p y=请输入除数:
- set /p n=请输入欲保留的小数的位数:
- set /a count=0
- set /a bjsh=10
- :loop
- if %count% geq %n% goto start
- set /a bjsh*=10
- set /a count+=1
- goto loop
- :start
- set /a rest=%x%*%bjsh%/%y%-%x%*%bjsh%/10/%y%*10
- if "%n%"=="0" (set /a last=%x%/%y%) else (
- set /a last=%x%*%bjsh%/10/%y%-%x%*%bjsh%/100/%y%*10
- )
- if %rest% geq 5 set /a last+=1
- if "%n%"=="0" echo 结果为%last% & pause & goto exit
- set /a result=%x%/%y%
- set result=%result%.
- set /a end=%n%-1
- set /a bjsh=10
- for /l %%i in (1,1,%end%) do (
- set /a add=%x%*!bjsh!/%y%-%x%*!bjsh!/10/%y%*10
- set result=!result!!add!
- set /a bjsh*=10
- )
- set result=%result%%last%
- echo 结果为%result% & pause
- :exit
BJSH发表于: 2007-04-01 13:30
作者: flyinspace
时间: 2007-4-2 02:46
哎。bjsh兄
楼主只是需要四舍五入。
你写那么多。有用么?
作者: bjsh
时间: 2007-4-2 03:01
呵呵
那倒是;
我只是顺手从发在你楼里的代码复制过来了