O'Reilly logo

Java Garage by Eben Hewitt

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

Real Numbers

The Java floating point types are float and double. Floating point types are numbers with a decimal place.

float

Occupies 32 bits or 4 bytes, with 6 or 7 significant digits

Default value of 0.0

Range: 6-7 significant decimal digits

Example: 3.1459F

You specify the float by placing an F literal after the float value. If you don't, the compiler will treat your number as a double.

Java floating point numbers follow the IEE754 specification, which includes positive and negative signed numbers, positive and negative zero, and a special value referred to as NaN (Not a Number).

NaN is used to represent the result of an illegal or invalid operation, such as an attempt to divide by zero. The Float and Double wrapper classes both have a method ...

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