批处理文件中的浮点分割 [英] Floating point division in a batch file

查看:85
本文介绍了批处理文件中的浮点分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在dos批处理中进行浮点除法.

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

返回整数.

有可能做到吗?

推荐答案

此类批处理文件不支持浮点运算.但是,本文建议使用一种外部脚本文件进行计算的解决方法.脚本文件应使用某种eval函数来评估作为参数传递的表达式并返回结果.这是执行此操作的示例VBScript文件( eval.vbs ):

Batch files as such do not support the floating point arithmetic. However, this article suggests a workaround that uses an external script file to do calculations. The script file should use some sort of eval function to evaluate the expression passed as an argument and return the result. Here's a sample VBScript file (eval.vbs) that does this:

WScript.Echo Eval(WScript.Arguments(0))

您可以从批处理文件中调用此外部脚本,指定要求值的表达式并返回结果.例如:

You can call this external script from your batch file, specify the expression to be evaluated and get the result back. For example:

@echo off
for /f %%n in ('cscript //nologo eval.vbs "10/3"') do (
  set res=%%n
)
echo %res%

当然,您将获得字符串形式的结果,但是总比没有好,您可以将获得的结果作为另一个表达式的一部分传递给eval脚本.

Of course, you'll get the result as a string, but it's better than nothing anyway, and you can pass the obtained result to the eval script as part of another expression.

这篇关于批处理文件中的浮点分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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