Rounding Error

The decimal system is not well-suited to displaying or calculating with certain types of numbers. What is the fraction 1/3, when calculated and displayed as a decimal by Java? (Note that you’ll need to calculate 1.0 / 3. If you only use integers 1 and 3 as your dividend and divisor, then you’ll get an integer division which is the whole number result of that division, or 0.)

This loss of precision occurs in the effort to express the same number in different systems.

In a similar fashion, when computers perform binary arithmetic using binary values converted from decimal imprecision can result. Write a program RoundingError.java that performs the calculation 4.35 * 100, stores the result in a double variable, and then prints out that result. Is it what you expected?

Have your program do two more calculations: 0.04 + 0.01, and 0.05 + 0.01. Which one works as expected? Which one doesn’t?