Java BigDecimal Round round(BigDecimal number)

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

Description

Round to two decimal places

License

Apache License

Declaration

public static BigDecimal round(BigDecimal number) 

Method Source Code

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

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

import java.text.DecimalFormat;

public class Main {
    /**/*from   w w  w.j  av a 2s .  com*/
     * Round to two decimal places
     */
    public static BigDecimal round(BigDecimal number) {
        return number.setScale(2, RoundingMode.HALF_UP);
    }

    public static String round(double weight) {
        DecimalFormat format = new DecimalFormat("#.#");
        format.setRoundingMode(RoundingMode.HALF_UP);
        return format.format(weight);
    }
}

Related

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