created: 02/15/98; revised: 07/31/99, 01/18/00, 06/01/00, 05/11/03, 01/13/06, 07/15/10, 05/05/2012, 06/10/2014, 07/15/2017

go to home page   go to next page hear noise highlighting

CHAPTER 13 — Floating Point

Java includes the primitive types float and double which hold floating point numbers.

When written with characters, floating point numbers include a decimal point followed by a decimal fraction. For example, 3.14159 and -0.718802. But (of course), inside the computer floating point numbers are represented with bit patterns, as is all data.

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 usually use arguments of type double, and usually return values of type double.

Note: the character that is used to separate the whole part of the number from the fractional part depends on what country you are in. In the U.S. (and other countries with a historical tie to England) a dot is used. In many other countries (most of Europe and South America) a comma is used. These notes use a dot.

Chapter Topics:


QUESTION 1:

Which uses more bits: a Java float or a Java double ?


go to home page   go to next page