How can I add two decimal number in bash?? For instance this
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")
You can use bc
, it should work with decimal calculations:
LAT=37.748944
LNG=-122.4175548
D=0.01
somecommand --position "$(echo "$LAT + $D" | bc), $(echo "$LNG + $D" | bc)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With