可能用批处理作个计算器吗?要能显示小数的
比如9除以4=2.25
[ Last edited by 26933062 on 2007-2-6 at 04:44 PM ]
比如9除以4=2.25
[ Last edited by 26933062 on 2007-2-6 at 04:44 PM ]
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off
setlocal enabledelayedexpansion
:begin
cls
set num=0
set dec_str=
set input=
set /p input= 请输入以空格分隔的被除数、除数和精确度:
for /f "delims=" %%i in ("%input%") do call :count %%i
:count
set /a int_str=%1/%2
set /a mod=%1%%%2
if %mod% equ 0 goto end
:count_dec
set mod=%mod%0
if %mod% lss %2 (
set dec_str=!dec_str!0
goto count_dec
) else (
set /a dec=%mod%/%2
set dec_str=!dec_str!!dec!
set /a mod=%mod%%%%2
)
set /a num+=1
if %mod% neq 0 if %num% lss %3 goto count_dec
:end
for /l %%i in (1,1,%3) do set zero_str=!zero_str!0
set dec_str=%dec_str%%zero_str%
cls
echo.&echo.&echo.
echo %1÷%2=%int_str%.!dec_str:~0,%3! ^(保留 %3 位小数^)
echo.
pause
goto begin
Originally posted by 26933062 at 2007-2-7 01:29 AM:
set /a mod=%1%%%2
请问这是什么意识?
set /a mod=9%%4 这样写可以吗?
但是我再 echo %mod% 不对啊??????
Originally posted by anqing at 2007-2-7 12:20:
但输入23 12 2和输入23 12 3,都是1.90 和1.900
如果精确到2位的话,应该是1.91,如果三位则是1.916才是呀?
为什么9后面全是0代替呀,和楼主的意思不符吧?