Floating point division in a batch file

后端 未结 8 926
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 21:48

I need to do a floating-point division in a dos batch.

I didn\'t find a way to do it. Something like this :

SET /A Res=10/3

returns

8条回答
  •  时光说笑
    2020-11-27 22:15

    I wrote a pure batch file specifically to do division. It takes the first number you input, and then divides it by the second one, and displays the result with as many decimal points as you specify.

    Echo off
    cls
    if NOT "%3" == "" (
    set n1=%1
    set n2=%2
    set max=%3
    goto :begin
    )
    
    set counter=2
    set n1=1
    set n2=1
    set ans=
    :start
    Echo.
    Echo. 1 / 2
    Echo.
    Set /p N1= 1?
    set /p N2= 2?
    Set /p Max= Out how many Decimal Points?
    :begin
    set /a TmpAns=%N1%/%N2%
    set ans=%TmpAns%.
    :: Echo.%ans%.>Answer.txt
    

    The answer put into the variable %Ans%. It can also be called with parameters. ("Divide.bat 50 27 5" would give you 50/27 out 5 decimal points.)

提交回复
热议问题