Given a Double real number, the task is to convert it into Integer in Java.
Examples:
Input: double = 3452.234 Output: 3452 Input: double = 98.23 Output: 98
- Using typecasting: This technique is a very simple and user friendly.
Syntax:
double data = 3452.345 int value = (int)data;
Example:
// Java program to convert Double to int// using TypecastingpublicclassGFG {// main methodpublicstaticvoidmain(String args[]){// Get the double valuedoubledata =3452.345;// convert into intintvalue = (int)data;// print the int valueSystem.out.println(value);}}chevron_rightfilter_noneOutput:
3452
- Using Math.round(): This method returns the nearest integer.
Syntax:
double data = 3452.645 int value = (int)Math.round(data);
Example:
// Java program to convert Double to int// using Math.round()publicclassGFG {// main methodpublicstaticvoidmain(String args[]){// Get the double valuedoubledata =3452.345;// convert into intintvalue = (int)Math.round(data);// print the int valueSystem.out.println(value);}}chevron_rightfilter_noneOutput:3452
- Using Double.intValue(): This technique is similar to typecasting method. Wrapper class Double truncates all digits after decimal point.
Syntax:
double data = 3452.345 Double newData = new Double(data); int value = newData.intValue();
Example:
// Java program to convert Double to int// using using Double.intValue()publicclassGFG {// main methodpublicstaticvoidmain(String args[]){// Get the double valuedoubledata =3452.345;// Create a wrapper around// the double valueDouble newData =newDouble(data);// convert into intintvalue = newData.intValue();// print the int valueSystem.out.println(value);}}chevron_rightfilter_noneOutput:3452
- Java Guava | Doubles.indexOf(double[] array, double target) method with Examples
- Java Guava | Doubles.indexOf(double[] array, double[] target) method with Examples
- Program to Convert Set of Integer to Array of Integer in Java
- Convert String to Double in Java
- How to Convert a Double value to String value in Java with Examples
- Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples
- Integer.valueOf() vs Integer.parseInt() with Examples
- Program to convert List of Integer to List of String in Java
- Program to Convert Set of Integer to Set of String in Java
- Program to convert set of String to set of Integer in Java
- Program to convert List of String to List of Integer in Java
- Java Program to convert boolean to integer
- Java Program to convert integer to boolean
- Java Program to Convert Integer Values into Binary
- Java.Lang.Double class in Java
- Convert IP address to integer and vice versa
- Double Brace Initialization in Java
- Comparison of double and float primitive types in Java
- DoubleStream reduce(double identity, DoubleBinaryOperator op) in Java with Examples
- Double byteValue() Method in Java with Examples
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

