Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add two decimal number in bash script [duplicate]

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")
like image 454
Guig Avatar asked Oct 16 '25 19:10

Guig


1 Answers

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)"
like image 165
mxmehl Avatar answered Oct 18 '25 14:10

mxmehl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!