intermediateJava Basics & OOP

Why should you never use double for financial calculations?

Binary floating point can't represent most decimal fractions exactly — `0.1 + 0.2` prints `0.30000000000000004`. Use BigDecimal with the String constructor (`new BigDecimal("0.1")`, never the double constructor) for exact decimal arithmetic; it's 5-10x slower but correctness matters more for money.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why does volatile guarantee visibility but not atomicity?← Back to all Core Java questions