在 bash 脚本中添加两位小数
Add two decimal number in bash script
如何在 bash 中添加两位小数??
比如这个
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(( LAT + D )), $(( LNG + D ))"
失败
37.748944: syntax error: invalid arithmetic operator (error token is ".748944")
您可以使用 bc
,它应该适用于小数计算:
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(echo "$LAT + $D" | bc), $(echo "$LNG + $D" | bc)"
如何在 bash 中添加两位小数?? 比如这个
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(( LAT + D )), $(( LNG + D ))"
失败
37.748944: syntax error: invalid arithmetic operator (error token is ".748944")
您可以使用 bc
,它应该适用于小数计算:
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(echo "$LAT + $D" | bc), $(echo "$LNG + $D" | bc)"