bash 在bash脚本中添加两个十进制数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38751037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:58:27 来源:igfitidea点击:
Add two decimal number in bash script
提问by Guig
How can I add two decimal number in bash?? For instance this
如何在bash中添加两个十进制数?例如这个
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(( LAT + D )), $(( LNG + D ))"
fails with
失败
37.748944: syntax error: invalid arithmetic operator (error token is ".748944")
回答by mxmehl
You can use bc
, it should work with decimal calculations:
您可以使用bc
,它应该适用于十进制计算:
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(echo "$LAT + $D" | bc), $(echo "$LNG + $D" | bc)"