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

查看:29
本文介绍了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

我收到错误:缺少操作员".输出(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

这篇文章.

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

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