Home » Java Float intValue() method with Examples

Java Float intValue() method with Examples

by Online Tutorials Library

Java Float intValue() Method

The intValue() method of Java Float class returns the integer value of this Float Object by simply narrowing primitive conversion.

Syntax:

Parameters:

NA

Return Value:

This method returns an int value for this float object.

Example 1

Test it Now

Output:

Multiplication of float values, 67.009*0.789 = 52.870102  Multiplication of integer values, 67.009*0.789 = 0  

Example 2

Test it Now

Output:

Enter the number to be reversed  78.90  Integer value = 78  Reversed int number = 87  

Example 3

Test it Now

Output:

Enter your marks in english  89.99  Marks after rounding off  : 90  

Example 4

Test it Now

Output:

Error:(8, 31) java: incompatible types: int cannot be converted to java.lang.Float  

Here, we are converting float (f2) into integer by intValue() method and without an explicit cast, we are placing it into float (f4). Either we should put it into int or should directly call this method in println function otherwise, we will get an error.

Next TopicJava Float

You may also like