The float Keyword

The float is a Java keyword that may not be used as identifiers i.e. you cannot declare a variable or class with this name in your Java program.

The float Keyword

The float Keyword  

     

The float is a Java keyword that may not be used as identifiers i.e. you cannot declare a variable or class with this name in your Java program.

It is used to declare a variable, an expression or a method return value of type single-precision floating-point number. It is also a java primitive data type that represents single-precision 32-bit IEEE 754 floating point. It ranges from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative). Use a float (instead of double) to save memory in large arrays. We do not use this data type for the exact values such as currency. For that we have to use java.math.BigDecimal class. 

The syntax of declaring a float type variable is: 

float <variable-name> = <float-value>;

For example: 

float f = 106.65;  
float f = -500.12;

 To specify the single-precision variable, when initializing, type F to the left of the value. Here is an example: 

public class Main { 

  public static void main(String[] args) { 

  float area = 4.12F;

  System.out.print("area: ");

  System.out.print(area);

  }