Java float type

In this chapter you will learn:

  1. What is Java float type
  2. Value and size for Java float type
  3. How to create float literals
  4. Example - Java float literal

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    
    } //ww  w. j av  a 2  s.c  o  m
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. What is Java double type
  2. Size and value for Java double type
  3. Example - Java double type
  4. How to create double type Literals
  5. Literal Letter
  6. Scientific notation
  7. double value constant
  8. How to get the value of double infinity
  9. What is double type NaN(Not a Number)
Home »
  Java Tutorial »
    Java Langauge »
      Java Data Types
Java Primitive Data Types
Java boolean type
Java char type
Java char value escape
Java byte type
Java short type
Java int type
Java long type
Java float type
Java double type
Java String type
Java String Escape
Java String Concatenation