如何在 bash 中使用浮点运算? [英] How do I use floating-point arithmetic in bash?
本文介绍了如何在 bash 中使用浮点运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 Bash 脚本中划分两个图像宽度,但 bash 给了我 0
作为结果:
I am trying to divide two image widths in a Bash script, but bash gives me 0
as the result:
RESULT=$(($IMG_WIDTH/$IMG2_WIDTH))
我确实学习了 Bash 指南,我知道我应该使用 bc
,在互联网上的所有示例中,他们都使用 bc
.在 echo
中,我尝试将相同的内容放入我的 SCALE
中,但没有成功.
I did study the Bash guide and I know I should use bc
, in all examples in internet they use bc
. In echo
I tried to put the same thing in my SCALE
but it didn't work.
这是我在教程中找到的示例:
Here is the example I found in the tutorials:
echo "scale=2; ${userinput}" | bc
我怎样才能让 Bash 给我一个像 0.5
这样的浮点数?
How can I get Bash to give me a float like 0.5
?
推荐答案
你不能.bash 仅 处理整数;您必须委托给诸如bc
之类的工具.
You can't. bash only does integers; you must delegate to a tool such as bc
.
这篇关于如何在 bash 中使用浮点运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文