Funbit / ets2-telemetry-server

ETS2/ATS Telemetry Web Server + Mobile Dashboard
GNU General Public License v3.0
623 stars 206 forks source link

converting full estimated distance into user friendly format #77

Closed dualznz closed 8 years ago

dualznz commented 8 years ago

Hi all

I am unsure how to convert the Estimated Distance from likes of 2429998.91

which is really only 242 kms but the data feed is showing full

any help would be great, im confused on this one little thing

mike-koch commented 8 years ago

The telemetry server returns distances in meters (which is why you're seeing the 2429998.91). If you want to convert it, you will need to do some calculations by hand, like this (the below code is in JavaScript, but it should be similar to any other language):

var estimatedDistanceKm = data.navigation.estimatedDistance / 1000;

If you want to drop everything after the decimal place, you can use something like this:

var estimatedDistanceKm = Math.floor(data.navigation.estimatedDistance / 1000);
dualznz commented 8 years ago

cheers for the reply its now showing in this case 591782 which is 591, i really would like to remove the 782 as its not needed, any ideas?

cheers

mike-koch commented 8 years ago

If you divide the value by 1000, and then use Math.floor, it should return 591. See https://jsfiddle.net/um0euukk/.

Funbit commented 8 years ago

I suppose the topic may be closed.