Java Decimal Round roundDistanceFromMeterToKm(final double distanceInMeter)

Here you can find the source of roundDistanceFromMeterToKm(final double distanceInMeter)

Description

z.B.

License

LGPL

Parameter

Parameter Description
distanceInMeter a parameter

Return

distanz in kilometer, gerundet auf einen meter

Declaration

public static String roundDistanceFromMeterToKm(final double distanceInMeter) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {
    private static final int KILOMETER_IN_METER = 1000;

    /**//w  w w  . j a  v a2 s.  c  o m
     * z.B. aus 10123.234535 --> 10.123
     *
     * @param distanceInMeter
     * @return distanz in kilometer, gerundet auf einen meter
     */
    public static String roundDistanceFromMeterToKm(final double distanceInMeter) {
        final double distanceInKilometer = distanceInMeter / KILOMETER_IN_METER;
        final DecimalFormat format = new DecimalFormat("0.000"); //$NON-NLS-1$
        final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setDecimalSeparator('.');
        format.setDecimalFormatSymbols(dfs);
        return format.format(distanceInKilometer);
    }
}

Related

  1. roundAlloc(Double alloc)
  2. roundAndTruncate(double rawValue, int precision)
  3. roundDecimal(double d, int radix)
  4. roundDecimalPlaces(final double input, final int decimalPlaces)
  5. roundDecimals(double d, int numOfDec)
  6. roundDouble(double iVal)
  7. roundDouble(double num, int decimal)
  8. roundDouble(double numero, int ceros_a_la_derecha)
  9. roundDouble(Double val, int precision)