Slightly simplified the code
Brother flyinspace's words I need to think carefully
[ Last edited by bjsh on 2007-4-1 at 02:53 PM ]
BJSH posted on: 2007-04-01 14:43
- @echo off &SetLocal EnableDelayedExpansion
- set /p x=Please enter the dividend:
- set /p y=Please enter the divisor:
- set /p n=Please enter the number of decimal places to retain:
- 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 The result is: %last% & pause & goto exit
- if "%n%"=="1" set /a t=%x%/%y% && echo The result is: !t!.%last% & pause & goto exit
- set /a result=%x%*%bjsh%/100/%y%
- set /a end=%n%-1
- call echo The result is: %%result:~0,-%end%%%.%%result:~-%end%%%%%last%% && pause
- :exit
Brother flyinspace's words I need to think carefully
[ Last edited by bjsh on 2007-4-1 at 02:53 PM ]

DigestI