浮点师在DOS批处理 [英] Floating point division in a dos batch

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

问题描述

我需要做浮点师在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

返回一个整数。

是否有可能呢?

推荐答案

批处理文件本身不支持浮点运算。然而,<一个href=\"http://www.celticproductions.net/articles/11/batch+files/add+floating+point+numbers+in+batch+file.html\"相对=nofollow>这篇文章表明,使用外部脚本文件做计算的解决方法。该脚本文件应使用某种评估函数来计算作为参数传递的前pression并返回结果。下面是一个示例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))

您可以从您的批处理文件中调用这个外部脚本,指定ex pression进行评估并得到结果回来。例如:

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脚本另一位前pression的一部分。

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.

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

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