How can I get more decimals from an AWK substr division

Viewed 65

On OpenWRT, I have the following "expression" in a shell script:

gps2="$(echo -e "$gps" |awk -F , '/\,/ {print "&lat="(substr($2,0,2) + (substr($2,3) / 60.0)) "&lon=" (substr($4,0,3) + (substr($4,4) / 60.0)) ; fflush();}' | head -1 )"

$gps contains the following: +CGPSINFO,3752.036737,N,02344.725959,E,120301,125950.0,50.5,0.0,32.0

The result of $gps2 is this: &lat=37.8673&lon=23.7454

as you can see, i only have 4 decimals from (substr($2,3) / 60.0) and (substr($4,4) / 60.0) How can I get more decimals? lat= 52.036737 / 60 = 0.86727895 + 37 = 37.86727895 and not 37.8673 as per my result.

Any help Very much appreciated.

Thank you in advance.

DD

1 Answers
$ echo '3752.036737' | awk '{print "&lat="(substr($1,0,2) + (substr($1,3) / 60.0))}' CONVFMT='%.6f'
&lat=37.867279
Related