Fix conversion of NM to km, it was M->km not NM->km
Use floating point fabs() as otherwise we get integer behavior in C.