Skip to content

Home

Convert between miles and kilometers in JavaScript

Miles to kilometers

In order to convert from miles to kilometers, you can use the conversion formula km = mi * 1.609344.

const milesToKm = miles => miles * 1.609344;

milesToKm(5); // ~8.04672

Kilometers to miles

Conversely, the conversion formula from kilometers to miles is mi = km * 0.621371.

const kmToMiles = km => km * 0.621371;

kmToMiles(8.1) // 5.0331051

More like this

Start typing a keyphrase to see matching snippets.