Need few suggestions on a strange behavior in adding a double with ONLY 0.39 (strange number). First snippet has proper example with 0.38 and the second with 0.39
// code snippet 1 : Adding xxxx.38 to xxxx.00
double b =1031.38;
double a =1587.00;
System.out.println ("using double "+(a+b));
BigDecimal premium = BigDecimal.valueOf(a);
BigDecimal netToCompany = BigDecimal.valueOf(b);
double result =Double.parseDouble(premium.add(netToCompany).toString());
System.out.println("using BigDecimal "+result);
// correct Output xxxx.38 + xxxx.00 = xxxx.38
using double 2618.38
using BigDecimal 2618.38
***** ------------------------------ ******
// code snippet 2 : Adding xxxx.39 to xxxx.00
double b =1031.39;
double a =1587.00;
System.out.println("using double "+(a+b));
BigDecimal premium = BigDecimal.valueOf(a);
BigDecimal netToCompany = BigDecimal.valueOf(b);
double result = Double.parseDouble(premium.add(netToCompany).toString());
// wrong Output xxxx.39 + xxxx.00 = xxxx.3900000000003
using double 2618.3900000000003
using BigDecimal 2618.39