Java BigDecimal Format format(BigDecimal n, int prec)

Here you can find the source of format(BigDecimal n, int prec)

Description

Returns the BigDecimal value n with exactly 'prec' decimal places.

License

Apache License

Declaration

public static BigDecimal format(BigDecimal n, int prec) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    /**/*from w  ww  .  j  a va 2  s.c om*/
     * Returns the BigDecimal value n with exactly 'prec' decimal places. Zeroes
     * are padded to the right of the decimal point if necessary.
     */
    public static BigDecimal format(BigDecimal n, int prec) {
        return n.setScale(prec, BigDecimal.ROUND_HALF_UP);
    }
}

Related

  1. fmtBdToInt(BigDecimal bd)
  2. format(BigDecimal amount, String format)
  3. format(BigDecimal decData, int precision, int scale)
  4. format(BigDecimal decimal)
  5. format(BigDecimal n, int prec)
  6. format(BigDecimal no, String formatter)
  7. format(BigDecimal num)
  8. format(BigDecimal num)