Java BigDecimal Round roundDown(BigDecimal a)

Here you can find the source of roundDown(BigDecimal a)

Description

round Down

License

Open Source License

Declaration

public static int roundDown(BigDecimal a) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    private static final double MIN = 0.0000001;

    public static int roundDown(BigDecimal a) {
        if (isZero(a)) {
            return 0;
        }/*from  w  w w . j a v  a2 s .  co m*/
        int i = a.intValue();
        return i;
    }

    public static boolean isZero(double d) {
        return Math.abs(d) <= MIN;
    }

    public static boolean isZero(float f) {
        return Math.abs(f) <= MIN;
    }

    public static boolean isZero(BigDecimal bd) {
        if (bd == null) {
            return true;
        }

        return isZero(bd.doubleValue());
    }

    public static boolean isZero(Integer bd) {
        if (bd == null) {
            return true;
        }

        return isZero(bd.doubleValue());
    }

    public static int intValue(Integer a) {
        if (a == null) {
            return 0;
        }

        return a.intValue();
    }

    public static int intValue(BigDecimal a) {
        if (a == null) {
            return 0;
        }

        return a.intValue();
    }

    public static double doubleValue(BigDecimal bd) {
        if (bd == null) {
            return 0.0;
        }
        return bd.doubleValue();
    }

    public static double doubleValue(Integer bd) {
        if (bd == null) {
            return 0.0;
        }
        return bd.doubleValue();
    }
}

Related

  1. roundBigDecimal(Number value, double precision)
  2. roundCommercial(BigDecimal value, int decimalPlaces)
  3. roundDecimal(Object value)
  4. roundDecimals(Float d)
  5. roundDoubleAsBigDecimal(double d, int numberOfDecimals)
  6. rounded(BigDecimal amount)
  7. roundHalfUp2Scale(BigDecimal value)
  8. roundImpl(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode mode)
  9. roundingError(final BigDecimal dividend, final BigDecimal divisor, final int roundingMode)