Java Fraction Format formatNumber(double number, int val)

Here you can find the source of formatNumber(double number, int val)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(double number, int val) 

Method Source Code


//package com.java2s;

import java.math.BigDecimal;
import java.math.RoundingMode;

import java.text.NumberFormat;

public class Main {

    public static String formatNumber(double number, int val) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(val);
        nf.setMinimumFractionDigits(val);
        nf.setRoundingMode(RoundingMode.HALF_UP);
        nf.setGroupingUsed(false);//w ww  . ja  va 2  s.  co m
        return nf.format(number);
    }

    public static String formatNumber(BigDecimal number, int val) {
        if (number == null)
            return "";
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(val);
        nf.setMinimumFractionDigits(val);
        return nf.format(number);
    }
}

Related

  1. formatNumber(double num)
  2. formatNumber(double num)
  3. formatNumber(double number)
  4. formatNumber(double number)
  5. formatNumber(double number, int decimal)
  6. formatNumber(Double number, String pattern)
  7. formatNumber(Double numberToFormat, int decimalPlacement)
  8. formatNumber(double paramDouble, int paramInt)
  9. formatNumber(double pValue)