Java BigDecimal Round round(BigDecimal decimal)

Here you can find the source of round(BigDecimal decimal)

Description

round

License

LGPL

Declaration

public static BigDecimal round(BigDecimal decimal) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    public static BigDecimal round(BigDecimal decimal) {
        return new BigDecimal(Math.round(decimal.doubleValue()));
    }/*from w w  w .ja v a2  s  . c  o m*/

    public static BigDecimal round(BigDecimal v, int scale) {
        if (scale < 0) {
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }
        BigDecimal b = new BigDecimal(Double.toString(v.doubleValue()));
        BigDecimal one = new BigDecimal("1");
        return b.divide(one, scale, BigDecimal.ROUND_HALF_UP);
    }
}

Related

  1. round(BigDecimal amount)
  2. round(BigDecimal aValue, int aScale)
  3. round(BigDecimal b, int precision)
  4. round(BigDecimal d, int decimalDigits, RoundingMode rmode)
  5. round(BigDecimal d, int decimalPlace)
  6. round(BigDecimal decimal)
  7. round(BigDecimal decimal, int decimalDigits)
  8. round(BigDecimal decimal, int precision)
  9. round(BigDecimal dividend, int divisor)