Java tutorial
//package com.java2s; import java.text.DecimalFormat; public class Main { /** Multiplier for km to miles. **/ private static final double MILES_CONVERT = 0.621371192; /** * Convert a number of kilometers to miles. * @param km number of km to convert * @return number of km in miles */ public static double asMiles(final double km) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(km * MILES_CONVERT)); } public static double asMiles(final long meters) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(asMiles(meters / 1000.0))); } }