mercredi 6 mai 2015

Is there any condition where Bigdecimal with MathContext.DECIMAL32 does not provides correct result?

System.out.println("Result="+new BigDecimal(((63.19* 15) + (63.37* 5))).divide(new BigDecimal(15 + 5), MathContext.DECIMAL64).doubleValue());

Result=63.23499999999999

But with MathContext.DECIMAL32 we are getting correct result, see below:

System.out.println("Result="+new BigDecimal(((63.19* 15) + (63.37* 5))).divide(new BigDecimal(15 + 5), MathContext.DECIMAL32).doubleValue());

Result=63.235

Aucun commentaire:

Enregistrer un commentaire