our application reads six decimal amounts from mongo documents and does mathematical operations. The amounts stored in mongo as string and java application reads as BigDecimal. In one of the instances we observed that the application has omitted the decimal and performed mathematical operations, while for other cases it’s working perfectly fine. And for the same amount also we are unable to replicate the issue. To be more specific, it did read “0.405504” as 405504 for just one time. Could you please share your thoughts/experience on what might have gone wrong and how to ensure this not recurring.
DecimalFormat df = new DecimalFormat();
df.setGroupingUsed(false);
df.setNegativePrefix(“-”);
DecimalFormatSymbols symbols = df.getDecimalFormatSymbols();
symbols.setDecimalSeparator(‘.’);
symbols.setGroupingSeparator(Character.MIN_VALUE);
df.setDecimalFormatSymbols(symbols);
df.setParseBigDecimal(true);
(BigDecimal) df.parse(“0.405504”);
Mongo Version : 5.0.25
Mongo Driver Core : 5.2.1
Java 17.0.12