Java BigDecimal Format formatNumberByMaxFrac(BigDecimal number, int val)

Here you can find the source of formatNumberByMaxFrac(BigDecimal number, int val)

Description

format Number By Max Frac

License

Open Source License

Declaration

public static String formatNumberByMaxFrac(BigDecimal number, int val) 

Method Source Code


//package com.java2s;

import java.math.BigDecimal;

import java.text.NumberFormat;

public class Main {

    public static String formatNumberByMaxFrac(double number, int val) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(val);
        nf.setGroupingUsed(false);/*  w w w  .  ja  va2 s . c o  m*/
        return nf.format(number);
    }

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

Related

  1. formatMoney(BigDecimal money, int scale, double divisor)
  2. formatMoney(long value)
  3. formatNoDecimalPoint(double amt)
  4. formatNumber(double number)
  5. formatNumber(String format, BigDecimal number)
  6. formatNumberByMaxFracUseGrp(BigDecimal number, int val)
  7. formatNumberCroreFormat(final BigDecimal num)
  8. formatNumberDouble(Double amount, int scale)
  9. formatNumberStr(String numberStr, Integer scale)