Java float type

float type

float type represents single-precision numbers.

float type variables are useful when you need a fractional component. Here are some example float variable declarations:

float high, low;

Value and size

float is 32-bit width and its range is from 1.4e-045 to 3.4e+038 approximately.

Literals

Floating-point literals in Java default to double precision. To specify a float literal, you must append an F or f to the constant.

Example 1

The following code shows how to declare float literals.


public class Main { 
    public static void main(String args[]) { 
        float d =  3.14159F; 
        System.out.print(d);//3.14159    
    } //from  www .  ja v  a2  s. c  om
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Language »




Java Data Type, Operator
Java Statement
Java Class
Java Array
Java Exception Handling
Java Annotations
Java Generics
Java Data Structures