Example usage for java.math RoundingMode HALF_UP

List of usage examples for java.math RoundingMode HALF_UP

Introduction

In this page you can find the example usage for java.math RoundingMode HALF_UP.

Prototype

RoundingMode HALF_UP

To view the source code for java.math RoundingMode HALF_UP.

Click Source Link

Document

Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.

Usage

From source file:Main.java

public static BigDecimal amtToBigDecimal(String bcdAmt) {
    BigDecimal bigDecimal = new BigDecimal(bcdAmt);
    bigDecimal.setScale(2, RoundingMode.HALF_UP);
    bigDecimal = bigDecimal.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
    return bigDecimal;
}

From source file:Main.java

public static String round(double value) {
    DecimalFormat decimalFormat = new DecimalFormat("0.00");
    decimalFormat.setRoundingMode(RoundingMode.HALF_UP);

    return decimalFormat.format(value);
}

From source file:Main.java

public static BigDecimal redondear(double f, int scale) {
    String val = f + "";
    BigDecimal big = new BigDecimal(val);
    big = big.setScale(scale, RoundingMode.HALF_UP);

    return big;// w  ww  .  j a va  2s  . co m
}

From source file:Main.java

private static BigDecimal getShareAmount(Double amount, Double rate, Integer installments) {
    return new BigDecimal(amount * ((1 + rate / 100) / installments)).setScale(2, RoundingMode.HALF_UP);
}

From source file:Main.java

public static float getDecreasePay(int amount, double monthRate, int totalMonth) {
    double v = amount / totalMonth * monthRate;
    return BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_UP).floatValue();
}

From source file:Main.java

public static double round(double value, int places) {

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:Main.java

private 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();
}

From source file:Main.java

public static float 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.floatValue();
}

From source file:Main.java

public static int getFirstMonthPay(int amount, double monthRate, int totalMonth) {
    double firstMonthPay = (amount / totalMonth) + amount * monthRate;
    return BigDecimal.valueOf(firstMonthPay).setScale(2, RoundingMode.HALF_UP).intValue();
}

From source file:Main.java

public static BigDecimal subtractVatAmount(BigDecimal percentage, BigDecimal amount) {
    BigDecimal f = BigDecimal.ONE
            .subtract(BigDecimal.ONE.divide(percentage.add(HUNDRED).divide(HUNDRED), 14, RoundingMode.HALF_UP));
    return amount.multiply(f).setScale(2, RoundingMode.HALF_UP);
}