How to convert double to int in Java
Example:
Input: num=1320.5
Output: 1320
Approach: 1:
Java
public class DoubleToInt {public static void main(String[] args) {double num = 1320.5;int dou = doubleToInt(num);System.out.println("int is " + dou);}private static int doubleToInt(double num) {return (int) num;}}
Approach : 2: Using intValue()
Java
public class DoubleToInt {public static void main(String[] args) {Double num = 1320.5;int dou = doubleToInt(num);System.out.println("int is " + dou);}private static int doubleToInt(Double num) {return num.intValue();}}
No comments:
Post a Comment