Java BigDecimal Format formatBigDecimal(BigDecimal number, int val)

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

Description

format Big Decimal

License

Open Source License

Declaration

public static String formatBigDecimal(BigDecimal number, int val) 

Method Source Code


//package com.java2s;

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

import java.text.DecimalFormat;

public class Main {

    public static String formatBigDecimal(BigDecimal number, int val, boolean isForceMax) {
        DecimalFormat nf = new DecimalFormat();
        nf.setMaximumFractionDigits(val);
        if (isForceMax)
            nf.setMinimumFractionDigits(val);
        nf.setRoundingMode(RoundingMode.HALF_UP);
        nf.setGroupingUsed(false);/*from   www.j a v a 2s  .  c om*/
        return nf.format(number);
    }

    public static String formatBigDecimal(BigDecimal number, int val) {
        DecimalFormat nf = new DecimalFormat();
        nf.setMaximumFractionDigits(val);
        nf.setMinimumFractionDigits(val);
        nf.setRoundingMode(RoundingMode.HALF_UP);
        nf.setGroupingUsed(true);
        return nf.format(number);
    }
}

Related

  1. formatBigDecimal(BigDecimal bd, NumberFormat format)
  2. formatBigDecimal(BigDecimal bigDecimal)
  3. formatBigDecimal(BigDecimal bigDecimal, int scale)
  4. formatBigDecimal(BigDecimal d)
  5. formatBigDecimal(BigDecimal n, int dp)
  6. formatBigDecimal(BigDecimal valor, int decimal)
  7. formatBigDecimal(BigDecimal value, char thousandSep, char decimalPoint, int numDecimals)
  8. formatBigDecimal(String value)
  9. formatBigDecimalWithPrecise(BigDecimal number)