在 bash 脚本中添加两位小数

Gui*_*uig 3 bash decimal addition

如何在bash中添加两个小数?例如这个

LAT=37.748944
LNG=-122.4175548
D=0.01

somecommand --position "$(( LAT + D )), $(( LNG + D ))"
Run Code Online (Sandbox Code Playgroud)

失败了

37.748944: syntax error: invalid arithmetic operator (error token is ".748944")
Run Code Online (Sandbox Code Playgroud)

mxm*_*ehl 7

您可以使用bc,它应该适用于小数计算:

LAT=37.748944
LNG=-122.4175548
D=0.01

somecommand --position "$(echo "$LAT + $D" | bc), $(echo "$LNG + $D" | bc)"
Run Code Online (Sandbox Code Playgroud)