Java Decimal Format decimalFormatLabel(final long value, final long divider, final String unit)

Here you can find the source of decimalFormatLabel(final long value, final long divider, final String unit)

Description

Formats a decimal value using a specified divider

License

Apache License

Parameter

Parameter Description
value the value to format
divider the divider to use
unit the unit label to append

Return

the decimal formatted label

Declaration

private static String decimalFormatLabel(final long value,
        final long divider, final String unit) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {
    /**/*from  www  . ja  v a 2 s . c o  m*/
     * Formats a decimal value using a specified divider
     * 
     * @param value the value to format
     * @param divider the divider to use
     * @param unit the unit label to append
     * @return the decimal formatted label
     */
    private static String decimalFormatLabel(final long value,
            final long divider, final String unit) {
        final double result = divider > 1 ? (double) value
                / (double) divider : (double) value;
        return new DecimalFormat("#,##0.#").format(result) + " " + unit;
    }
}

Related

  1. decimalFormat(Double numeric)
  2. decimalFormat(double value, int decimalCnt)
  3. decimalFormat(Object obj)
  4. decimalFormat(String pattern)
  5. decimalFormat(String pattern, double value)
  6. decimalPointTwo(Float input)
  7. decimalString(double d, boolean forceDigits)
  8. encodeDouble(double d)
  9. getCorrectionValue(double basicValue, int digit)