Java BigDecimal Round round(BigDecimal value, int places)

Here you can find the source of round(BigDecimal value, int places)

Description

round

License

Apache License

Declaration

public static BigDecimal round(BigDecimal value, int places) 

Method Source Code


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

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static double round(double value, int places) {
        if (places < 0)
            throw new IllegalArgumentException();

        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(places, RoundingMode.HALF_UP);
        return bd.doubleValue();
    }/*w w w .j  ava2 s  .  c  o  m*/

    public static BigDecimal round(BigDecimal value, int places) {
        if (places < 0)
            throw new IllegalArgumentException();

        value = value.setScale(places, RoundingMode.HALF_UP);
        return value;
    }
}

Related

  1. round(BigDecimal v, int scale, int roundingMode)
  2. round(BigDecimal value)
  3. round(BigDecimal value)
  4. round(BigDecimal value, BigDecimal increment, RoundingMode roundingMode)
  5. round(BigDecimal value, int accuracy)
  6. round(BigDecimal value, String currency)
  7. round(BigDecimal what, int howmuch)
  8. round(final BigDecimal input, final int precision)
  9. round(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode roundingMode)