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