中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
作者:
标题: 【分享】计算循环小数 上一主题 | 下一主题
maidu
社区乞丐





积分 -66
发帖 40
注册 2008-3-25
状态 离线
『楼 主』:  【分享】计算循环小数

@echo off 
setlocal EnableDelayedExpansion 

if %2.==. goto input 
set /A N=%1 
set /A D=%2 
goto compute 

:input 
echo Input N: 
set /p NN= 
set /A N=%NN% 
echo Input D: 
set /p DD= 
set /A D=%DD% 
goto compute 

:compute 
if %N%==0 echo Wrong Intry && goto input 
if %D%==0 echo Wrong Intry && goto input 
set str= 

for /L %%a in (1,1,%D%) do @set /A Left%%a=0 
for /L %%a in (1,1,%D%) do @set /A Result%%a=0 
set /A int_part="%N%/%D%" 
set /A N="%N%%%%D%" 
set /A tool=%N% 
if %tool%==0 echo The result of expression "%N%/%D%" is %int_part% && goto :EOF 
set /A turn=1 

:start 
set /A "tool*=10" 
set /A Result%turn%="%tool%/%D%" 
set /A Left="%tool%%%%D%" 
if %Left%==0 set /A begin=-1 && set /A end="%turn%" && goto endCompute 
if %Left%==%N% set /A begin=0 && set /A end="%turn%" && goto endCompute 
if not !Left%Left%!==0 set /A begin="!Left%Left%!" && set /A end="%turn%" && goto endCompute 

set /A Left%Left%=%turn% 
set /A tool=%Left% 
set /A "turn+=1" 
goto start 

:endCompute 
if %3.==. echo The result of expression "%N%/%D%" is  
set result=# 
for /L %%i in (1,1,%end%) do @set result=!result!!Result%%i! 
set result=%result:~1% 
if %begin%==-1 echo %int_part%.%result% && goto end 
if %begin%==0 echo %int_part%.[%result%] && goto end 
echo %int_part%.!result:~0,%begin%![!result:~%begin%!] 

:end 
if %2.==. echo. && echo Press any key to quit application && pause>nul
[ Last edited by maidu on 2008-4-19 at 05:39 AM ]


2008-4-19 04:50
查看资料  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: