Java BigDecimal Round round(BigDecimal decimal)

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

Description

Rounds the value to a long using java.math.RoundingMode#HALF_UP

License

Apache License

Parameter

Parameter Description
decimal the value to round

Return

rounded value

Declaration

static long round(BigDecimal decimal) 

Method Source Code


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

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

public class Main {
    private static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP;

    /**//from  w  w w .  j a v a  2s  . c  om
     * Rounds the value to a long using {@link java.math.RoundingMode#HALF_UP}
     *
     * @param decimal the value to round
     * @return rounded value
     */
    static long round(BigDecimal decimal) {
        return decimal.setScale(0, ROUNDING_MODE).longValue();
    }

    static long round(Double decimal) {
        return round(BigDecimal.valueOf(decimal));
    }
}

Related

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