Home Java Java-conversion Convert Float to Integer
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Convert Float to Integer

Advertisement
In this section, we will learn to convert a float type data into an integer.

Convert Float to Integer

     

In this section, we will learn to convert a float type data into an integer. 

Code Description:

In this program, first of all we declare a float variable named 'f'. Which is stored the value  '10.0F'. Here the is the '10.0F' is used for  representing the float type number. If the F can't be applied at the end of the value, the result has been a double and it is not a float. 

For converting the float type value into an integer, we simply applied the type casting process and get the integer value.

Here is the code of this program:

public class  FloatToInt{
  static float f = 10.0F;
  
  public static void main(String arg[]){
  int i = (int)f;
  System.out.println("Float data: " + f);
  System.out.println("Integer data: " +i);
  }
}

Download this program:

Output this program.

 C:\corejava>java FloatToInt
 9,9.0
C:\corejava>
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: July 4, 2007

Related Tutorials

Ask Questions?    Discuss: Convert Float to Integer  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Aaron
January 24, 2012
How to convert a float type data into an integer.

Thank you so much!!!. I got the right solution for my question.
Andrew Cesario
June 4, 2012
thank you!

thanks for the information.
DMCA.com