[英]How to multiply decimals using expr
When I run the following command:当我运行以下命令时:
expr 1.2 * 13
I get this error:我收到此错误:
expr: syntax error: unexpected argument '12'
I expect I am missing a syntax.我希望我缺少语法。 What is it?它是什么?
The asterisk is expanded as a glob, so you'll end-up running something like expr 1.2 file1 file2 13
星号被扩展为一个 glob,所以你最终会运行类似expr 1.2 file1 file2 13
的东西
Also, the shell cannot do arithmetic with floating point numbers:此外,shell无法对浮点数进行算术运算:
expr 1.2 \* 13
expr: non-integer argument
You'll need to use a command like bc
/ awk
/etc... or convert your numbers to integers:您需要使用像bc
/ awk
/etc... 这样的命令或将您的数字转换为整数:
echo '1.2 * 13' | bc
15.6
awk 'BEGIN{ print 1.2 * 13 }'
15.6
expr 12 \* 13 / 10
15
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.