Skip to main content
The float data type in Java is a single-precision 32-bit IEEE 754 floating-point primitive. It is designed to represent fractional numbers, allocating memory into three distinct components: a 1-bit sign, an 8-bit exponent, and a 23-bit mantissa (fraction).

Technical Specifications

  • Memory Size: 32 bits (4 bytes)
  • Default Value: 0.0f
  • Precision: 6 to 7 significant decimal digits
  • Minimum Positive Non-zero Value: 1.4E-45f (Float.MIN_VALUE)
  • Maximum Value: 3.4028235E38f (Float.MAX_VALUE)
  • Wrapper Class: java.lang.Float

Syntax and Initialization

In Java, floating-point literals default to the 64-bit double type. To explicitly declare a float literal, you must append the f or F suffix. Omitting the suffix results in a compilation error due to a lossy conversion from double to float.

Special Values

The IEEE 754 standard defines specific bit patterns for non-standard numerical states. Java exposes these through constants in the Float wrapper class:

Type Conversion and Casting

float participates in Java’s primitive type promotion and casting rules:
  • Widening (Implicit): float can be implicitly promoted to double.
  • Narrowing (Explicit): Converting a double to a float requires an explicit cast, which truncates the mantissa and rounds the value, potentially resulting in precision loss or Infinity if the value exceeds Float.MAX_VALUE.
  • Integer to Float: long (64-bit) and int (32-bit) can be implicitly converted to float. However, because float only has 23 bits of precision for the mantissa, converting large integers may result in a loss of least significant digits.
Tired of Poor Java Skills? Fix That With Deep Grasping!Learn More