Get the latest tech news
Pitfalls of comparing BigDecimals in Java
Learn how to accurately compare Java BigDecimal with real examples. Discover when to use compareTo() and how to normalize scales for precise results
When working with floating-point numbers in Java, developers often turn to the BigDecimal class for precise calculations. One common mistake developers make is assuming that the equals() method in BigDecimal compares the numerical values. Keep these considerations in mind when working with BigDecimals to avoid unexpected results in your Java programs.
Or read this on Hacker News