Java BigDecimal Round round(BigDecimal v, int scale, int roundingMode)

Here you can find the source of round(BigDecimal v, int scale, int roundingMode)

Description

round

License

Open Source License

Declaration

public static BigDecimal round(BigDecimal v, int scale, int roundingMode) 

Method Source Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {

    public static int round(double v) {

        return round(new BigDecimal(v), 0, BigDecimal.ROUND_HALF_UP).intValue();
    }//www  . j a  v  a 2 s . c  o  m

    public static BigDecimal round(BigDecimal v, int scale, int roundingMode) {

        if (scale < 0 || roundingMode < 0) {
            throw new IllegalArgumentException("The scale or roundingMode must be a positive integer or zero");
        }

        return v.divide(BigDecimal.ONE, scale, roundingMode);
    }

    public static BigDecimal divide(String v1, String v2) {

        return divide(new BigDecimal(v1), new BigDecimal(v2));
    }

    public static BigDecimal divide(double v1, double v2) {

        return divide(new BigDecimal(v1), new BigDecimal(v2));
    }

    public static BigDecimal divide(BigDecimal v1, BigDecimal v2) {

        return divide(v1, v2, 2, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal divide(BigDecimal v1, BigDecimal v2, int scale, int roundingMode) {

        return v1.divide(v2, scale, roundingMode);
    }
}

Related

  1. round(BigDecimal dividend, int divisor)
  2. round(BigDecimal initData, int scale)
  3. round(BigDecimal money, int scale)
  4. round(BigDecimal num, int scale)
  5. round(BigDecimal number)
  6. round(BigDecimal value)
  7. round(BigDecimal value)
  8. round(BigDecimal value, BigDecimal increment, RoundingMode roundingMode)
  9. round(BigDecimal value, int accuracy)