Chapter 6

Using BigDecimals

In This Chapter

arrow Understanding the problem with double arithmetic in Java

arrow Solving the double problem with the BigDecimal class

arrow Creating objects with BigDecimal

arrow Doing arithmetic with BigDecimal objects

arrow 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.