How to convert Double to numeric primitive data types in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
  
        Double d = new Double("3.14");
        
        byte b = d.byteValue();
        System.out.println(b);

        short s = d.shortValue();
        System.out.println(s);

        int i = d.intValue();
        System.out.println(i);

        float f = d.floatValue();
        System.out.println(f);

        double dp = d.doubleValue();
        System.out.println(dp);
    }
}
 
/*
    
run:
    
3
3
3
3.14
3.14

*/

 



answered Nov 2, 2016 by avibootz

Related questions

1 answer 285 views
1 answer 244 views
1 answer 220 views
1 answer 227 views
1 answer 231 views
...