Java Number - intValue() Method
The java.lang.Number.intValue() method returns the value of the specified number as an int, which may involve rounding or truncation.
Syntax
public abstract int intValue()
Parameters
No parameter is required.
Return Value
Returns the numeric value represented by this object after conversion to type int.
Exception
NA.
Example:
In the example below, the java.lang.Number.intValue() method returns the int value of the given numbers.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a Float Float val1 = 10.25f; //creating a Double value Double val2 = 55.75; //printing the int value of given numbers System.out.println("int value of val1: " + val1.intValue()); System.out.println("int value of val2: " + val2.intValue()); } }
The output of the above code will be:
int value of val1: 10 int value of val2: 55
❮ Java.lang - Number