Home Help Java F The float Keyword
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

The float Keyword

Advertisement
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 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);

  }

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 17, 2009

Related Tutorials

Ask Questions?    Discuss: The float Keyword   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com