Java BigDecimal Round round(BigDecimal d, int decimalPlace)

Here you can find the source of round(BigDecimal d, int decimalPlace)

Description

round

License

Apache License

Declaration

public static double round(BigDecimal d, int decimalPlace) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    public static double round(BigDecimal d, int decimalPlace) {
        d = d.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
        return d.doubleValue();
    }//from  w w  w.  ja  va  2s . c  om

    public static double round(double d, int decimalPlace) {
        BigDecimal bd = new BigDecimal(Double.toString(d));
        bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
        return bd.doubleValue();
    }
}

Related

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