Sunday, June 15, 2014

Rounding Decimal places - Maths

public class TestRounding {
    public static void main(String args[]) {

        Object result1 = new BigDecimal(432295.084);
        Object result2 = new BigDecimal(432295.044);
        System.out.println(((BigDecimal) result1).setScale(1, BigDecimal.ROUND_HALF_DOWN));
        System.out.println(((BigDecimal) result2).setScale(1, BigDecimal.ROUND_HALF_DOWN));
    }
}


Output
Result1 Rounded to = 432295.1
Result2 Rounded to = 432295.0

No comments:

Post a Comment