Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

decimals in batch script

echo off
cls

mode con: cols=55 lines=15

:MAIN
color 07
cls

set /p num1="Specify first number: "
cls
set /p num2="Specify second number: "
cls

set /a num3=%num1%*%num2%

echo %num3%
pause

Say num1 = 30 and num2= .10 then it would only display 0 and not .3 so how do I make it do decimals and how would you display out to 5 decimals places if needed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Batch does not support floating point arithmetic. You have to rely on external scripts.

http://www.computing.net/howtos/show/batch-script-floating-point-math/753.html

Floating point division in a dos batch


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...