- @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 |
|