Pages

Sep 22, 2009

How to convert Miles to KM in javascript

Below is the simple method to convert Miles to KM.

function ConvertMileToKM(dist)
{
var distC = dist * 1; // to make the value as integer
var distKM = dist * 1.609344; // to convert into km
var distMile = distC.toFixed(2); // to round it to 2 decimal places.
}


To convert a string value to integer we can simply multiply with 1
stringvalue * 1 will give you a integer value