Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.DecimalFormat;

public class Main {
    /**
     * Format distance to be displayed to the user
     *
     * @param d , distance in metres
     *
     * @return formatted {@link String}
     */
    public static String formatDistance(double d) {
        DecimalFormat formatter = new DecimalFormat("#,### 'm'");
        d = Math.round(d);
        if (d > 1000) {
            formatter = new DecimalFormat("#,###.# 'km'");
            d = d / 1000;
        }

        return formatter.format(d);
    }
}