SET命令-浮点数? [英] SET Command - Floating point numbers?

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

问题描述

如何在Windows中使用SET命令进行浮点运算./A代表算术,%VAR%打印VAR的数据而不是名称.

How do I use the SET command in windows for floating point arithmatic. /A stands for arithmetic and %VAR% prints the data of VAR not the name.

例如,当我这样做时:

SET /A VAR="2.5+3.1"
ECHO %VAR%
pause

我收到错误消息:"Missing Operator". 输出(5.6)也应转换为浮点数

I get the error: 'Missing Operator'. The output (5.6) should be converted to floating point too

我还在忙着学习基本语法.

I'm still busy learning the basic syntax.

关于,狙击

推荐答案

SET/A命令的算术运算仅对32位整数执行;但是,如果选择许多小数位数并在整个操作过程中保留它们,则可以使用SET/A轻松地模拟定点运算.例如:

The arithmetic operations of SET /A command are performed over 32-bits integer numbers only; however, you may easily simulate fixed point operations with SET /A if you choose a number of decimal digits and preserve they throughout the operations. For example:

REM Select two decimal digits for all operations
SET /A VAR=250+310
ECHO RESULT: %VAR:~0,-2%.%VAR:~-2%

此方法使您可以直接执行两个固定点"数字的加法或减法.当然,如果要以通常的方式输入数字(带小数点),则在执行操作之前必须消除小数点并保留零.

This method allows you to directly perform addition or subtraction of two "Fixed Point" numbers. Of course, if you want to input numbers in the usual way (with decimal point), you must eliminate the decimal point and left zeros before perform the operations.

您也可以将FP(不动点)数字直接乘以或除以整数,结果是正确的.要对两个FP数字相乘或相除,我们可以使用一个称为ONE的辅助变量,该变量应具有正确的小数位数.例如:

You may also directly multiply or divide a FP (fixed point) number by an integer and the result is correct. To multiply or divide two FP numbers we may use an auxiliary variable called ONE with the correct number of decimal places. For example:

rem Set "ONE" variable with two decimal places:
SET ONE=100
rem To multiply two FP numbers, divide the result by ONE:
SET /A MUL=A*B/ONE
rem To divide two FP numbers, multiply the first by ONE:
SET /A DIV=A*ONE/B

有关更多详细信息,请参见这篇文章.

Further details at this post.

这篇关于SET命令-浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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