The first thing that comes to mind is to use float and double data types. The developers need to know what data type of Java is appropriate for representing floating-point values, especially monetary values. Using BigDecimal(double) is extremely dangerous because it may lose precision and unpredictable results.

4m read time From medium.com
Post cover image
Table of contents
How to use BigDecimal in Java accuratelyIntroductionWhy double is not accurateHow does BigDecimal ensure accuracyHow to create BigDecimal properlyWhat is wrong with BigDecimal(double)Creation using BigDecimal(String)ConclusionReferences

Sort: