get Distance Format - Java java.lang

Java examples for java.lang:double Format

Description

get Distance Format

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String unite = "java2s.com";
        long distance = 2;
        System.out.println(getDistanceAffichage(unite, distance));
    }//from  w  ww  . j  a  v  a 2 s . co  m

    public static String getDistanceAffichage(final String unite,
            final Long distance) {
        if ("km".equals(unite)) {
            String metres = "";
            if (distance % 1000 > 100) {
                metres = metres.concat(String.valueOf(distance % 1000));
            } else if (distance % 1000 < 10) {
                metres = metres.concat("00").concat(
                        String.valueOf(distance % 1000));
            } else if (distance % 1000 < 100) {
                metres = metres.concat("0").concat(
                        String.valueOf(distance % 1000));
            }
            return distance / 1000 + "km" + metres;
        }
        return null;
    }
}

Related Tutorials