Java Fraction Format formatNumber(double paramDouble, int paramInt)

Here you can find the source of formatNumber(double paramDouble, int paramInt)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(double paramDouble, int paramInt) 

Method Source Code


//package com.java2s;
import java.math.BigDecimal;
import java.text.NumberFormat;

public class Main {
    public static String formatNumber(double paramDouble, int paramInt) {
        return NumberFormat.getNumberInstance().format(round(paramDouble, paramInt));
    }/*from  ww  w  . jav  a 2 s. co  m*/

    public static double round(double paramDouble, int paramInt) {
        if (paramInt < 0) {
            throw new RuntimeException("The scale must be a positive integer or zero");
        }
        BigDecimal localBigDecimal1 = new BigDecimal(Double.toString(paramDouble));
        BigDecimal localBigDecimal2 = new BigDecimal("1");
        return localBigDecimal1.divide(localBigDecimal2, paramInt, 4).doubleValue();
    }
}

Related

  1. formatNumber(double number)
  2. formatNumber(double number, int decimal)
  3. formatNumber(double number, int val)
  4. formatNumber(Double number, String pattern)
  5. formatNumber(Double numberToFormat, int decimalPlacement)
  6. formatNumber(double pValue)
  7. formatNumber(double value)
  8. formatNumber(double value, double epsilon)
  9. formatNumber(final double number)