O'Reilly logo

Java All-in-One For Dummies, 4th Edition by Doug Lowe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required