Java BigDecimal Round round(BigDecimal decimal, int decimalDigits)

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

Description

round

License

Open Source License

Declaration

public static BigDecimal round(BigDecimal decimal, int decimalDigits) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    public static BigDecimal round(BigDecimal decimal, int decimalDigits) {
        BigDecimal scale = new BigDecimal(Math.pow(10, decimalDigits));
        return new BigDecimal(Math.round(decimal.multiply(scale).doubleValue())).divide(scale);
    }/* ww  w .  j ava2  s.  c o  m*/
}

Related

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