RoundingMode.HALF_UP does not give correct result

38 views Asked by At

I used code snippet below using RoundingMode.HALF_UP:

        Double value = new Double( "18.74");

        Double result = (value*75)/100;
        System.out.println("Result: "+result);

        BigDecimal roundedValue = BigDecimal.valueOf(result).setScale(2, RoundingMode.HALF_UP);
        System.out.println("Rounded Value: "+roundedValue);

It gave me the result below:

Result: 14.054999999999998
Rounded Value: 14.05

But the expected value should be 14.06 How fix the issue?Are there any suggestions?

0

There are 0 answers