created 02/15/98; revised: 07/31/99; 01/18/00; 06/01/00; 05/11/03

CHAPTER 11 — Floating Point

The Java primitive types include the floating point types float and double. Floating point numbers are those that include a fractional part. On paper, a floating point number includes a decimal point. For examples, 3.14159 and -0.718802.

In main storage, and in disk storage, a float is represented with a 32-bit pattern and a double is represented with a 64-bit pattern. For input from the keyboard, character data must be converted to floating point data. For output to the monitor or to a text file, floating point data are converted to characters.

All of the familiar mathematical functions such as sine, log, and square root are available to your program in the Java Math class. These functions typically expect floating point data.

If you don't like math, you can skip most of this chapter with little damage. But read the first few pages about how to read floating point numbers.

Chapter Topics:

Some of the methods in this chapter work only with Java versions 1.2 and higher.

QUESTION 1:

The data type int and the data type float both use 32 bits.

Is the pattern for the int value 221 the same as the pattern for the float value 221.0?