联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@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 if "%n%"=="1" set /a t=%x%/%y% && echo 结果为:!t!.%last% & pause & goto exit set /a result=%x%*%bjsh%/100/%y% set /a end=%n%-1 call echo 结果为:%%result:~0,-%end%%%.%%result:~-%end%%%%%last%% && pause :exit BJSH发表于: 2007-04-01 14:43
@echo off &SetLocal EnableDelayedExpansion set /p x=请输入被除数: set /p y=请输入除数: :n set /p n=请输入欲保留的小数的位数: if %n% gtr 7 echo 最大精确度为7位请重新输入 && goto n set /a count=0 set /a bjsh=10 set /a system_result=%x%/%y% set /a system_rest=%x%%%%y% set x=%system_rest% :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=%rest%) else ( set /a last=%x%*%bjsh%/10/%y%-%x%*%bjsh%/100/%y%*10 ) if "%n%"=="0" if %rest% geq 5 set /a last=%system_result%+1 && echo 结果为:!last! & pause & goto exit if %rest% geq 5 set /a last+=1 if "%n%"=="1" echo 结果为:%system_result%.%last% & pause & goto exit set /a result=%x%*%bjsh%/100/%y% set /a end=%n%-1 call echo 结果为:%%system_result%%.%%result:~-%end%%%%%last%% && pause :exit BJSH发表于: 2007-04-01 15:44
@echo off set /p x=请输入被除数: set /p y=请输入除数: set /p n=请输入欲保留的小数的位数: set /a end=%n%-1 set /a count=0 set /a system_result=%x%/%y% set /a rest=%x%%%%y% set result=%system_result%. :loop set /a rest*=10 set /a last=%rest%/%y% set /a count+=1 if %count% geq %n% set /a rest=%rest%%%%y%*10/%y% && goto jump_loop set result=%result%%last% set /a rest=%rest%%%%y% goto loop :jump_loop if %n%==0 if %last% geq 5 set /a result+=1 && echo 结果为:!result!&& goto exit if %rest% geq 5 set /a last+=1 echo %result%%last% & pause BJSH发表于: 2007-04-01 18:28
@echo off & setlocal enabledelayedexpansion set /p x=请输入被除数: set /p y=请输入除数: if %y% gtr 2000000000 echo 除数太大 && goto exit set /p n=请输入欲保留的小数的位数: if %x% gtr 2000000000 goto big :start set /a count=0 set /a system_result=%x%/%y% set /a rest=%x%%%%y% set result=%system_result%. :loop set /a rest*=10 set /a last=%rest%/%y% set /a count+=1 if %count% geq %n% set /a rest=%rest%%%%y%*10/%y% && goto jump_loop set result=%result%%last% set /a rest=%rest%%%%y% goto loop :jump_loop if %n%==0 if %last% geq 5 set /a result+=1 && echo 结果为:!result!&& goto exit if %rest% geq 5 set /a last+=1 echo 结果为:%result%%last% && goto exit :big set /a l=0 set result= :big_loop set p=%x:~0,1% set /a m=%l%*10+%p% set /a s=%m%/%y% set result=%result%%s% if "%result%"=="0" set result= set /a l=%m%%%%y% set x=%x:~1% if not defined x goto big_end goto big_loop :big_end set result=%result%. set /a count=0 set rest=%l% goto loop :exit pause BJSH发表于: 2007-04-01 18:56
Originally posted by bjsh at 2007-4-1 07:01 PM: 无法解决被除数大于10^9的问题