如何使用基本数学批处理命令来与小数的答案? [英] How do I use basic batch math commands to come up with decimal answers?

查看:322
本文介绍了如何使用基本数学批处理命令来与小数的答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个批处理文件,这样我就告诉它我需要用什么样的公式,它告诉我,我需要输入什么样的变量。现在,我编码它,以便它会发现一个三角形的面积。

I am making a batch file so that I just tell it what kind of formula I need to use and it tells me what variables I need to input. Right now, I am coding it so that it will find the area of a triangle.

我已经写了code,以便它要求你的基地,高度和三角形的单位。正如你应该知道,其公式为根本,基地x高/ 2。所以我测试了code,看看它是否工作。但我注意到,当它除以2为奇数,它并没有给小数的答案。它代替向下舍入数字。 (例:15/2 = 7)

I have written the code so that it asks you the base, height, and the units of the triangle. As you should know, the formula is simply, base x height / 2. So I tested the code to see if it works. But I noticed that when it divides an odd number by 2, it doesn't give a decimal answer. It instead rounds down a number. (Ex. 15/2=7)

下面是我的code:

    set /p TriangleB=How long is the base of the triangle? (Don't put the unit, just put the number):
    set /p TriangleH=What is the height of the triangle? (Don't put the unit, just put the number):
    set /p TriangleAreaUnit=What unit is the triangle being measured in?:
    set /a TriangleArea=%TriangleB% * %TriangleH% / 2
    echo The area of the triangle is %TriangleArea% %TriangleAreaUnit%.
    pause >nul
    goto :EOF

它没有给我任何错误消息,似乎一切都可以流畅运行,我只是想不通,为什么它不会给我一个小数的答案。

It doesn't give me any error message and everything seems to be running smoothly, I just can't figure out as to why it won't give me a decimal answer.

推荐答案

您可以尝试这样说,这与一个批处理文件:

You can try it like that with a batch file :

@echo off
set /p "TriangleB=How long is the base of the triangle ? (Don't put the unit, just put the number): "
set /p "TriangleH=What is the height of the triangle ? (Don't put the unit, just put the number): "
set /p "TriangleAreaUnit=What unit is the triangle being measured in ?: "
Call :makevbs %TriangleB% %TriangleH%
echo The area of the triangle is %TriangleArea% %TriangleAreaUnit%^2.
pause >nul
Exit /b

:makevbs
echo wscript.echo Eval( wscript.Arguments(0^) * wscript.Arguments(1^) / 2^) > "%tmp%\%~n0.vbs"
for /f %%A in ('cscript /nologo "%tmp%\%~n0.vbs" %~1 %~2') do set TriangleArea=%%A
exit /b

这篇关于如何使用基本数学批处理命令来与小数的答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆