DecimalFormat produces two different results on different machines

I analyzed the case when DecimalFormat rounded by one BigDecimal number, and on the other machine it is truncated.

I checked all the configurations on both machines (and they are all the same, I suppose). The only difference I found out is the version of the JDK.

Machine 1 runs on JDK1.6. But, I tried the same with JDK1.7 on Machine 1, it works the same as with JDK1.6.

Machine 2 runs on JDK1.7

The following is a snippet of code:

 DecimalFormat decimalFormat = new DecimalFormat("#,###.00"); BigDecimal anObject = new BigDecimal("3.8880"); String str = decimalFormat.format(((Number)anObject).doubleValue()); System.out.println(str); 

By car 1 Result: 3.39

By car 2 result: 3.38

+5
source share
1 answer

A bug appeared in DecimalFormat in DecimalFormat . See this question for more information: Is rounding mismatch between Java 7 and Java 8 an error?

+6
source

All Articles