Chapter 6
Using BigDecimals
In This Chapter
Understanding the problem with double arithmetic in Java
Solving the double problem with the BigDecimal class
Creating objects with BigDecimal
Doing arithmetic with BigDecimal objects
Discovering other things to do with BigDecimal
You would think that arithmetic would be one area in which any programming language would excel. After all, computers were conceived as enormous calculating machines.
Alas, Java doesn't always do arithmetic the way you'd like. In this chapter, you discover why. Then you work around Java's inherent arithmetic limitations by using a special class designed for just that purpose: the BigDecimal class. BigDecimal is a pain to use, but just about any program that does financial calculations should use it.
Seeing Why Java Can't Add
Every schoolboy (and schoolgirl) knows that ten pennies make a dime. You can write a Java program to prove this simple assertion. I created a double variable named dime and assigned it the ...
Get Java All-in-One For Dummies, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.