How to convert Float to numeric primitive data types in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
  
        Float fObj = new Float(3.14);

        byte b = fObj.byteValue();
        System.out.println(b);

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

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

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

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

3
3
3
3.14
3.140000104904175

*/

 



answered Nov 4, 2016 by avibootz

Related questions

1 answer 285 views
1 answer 244 views
1 answer 220 views
1 answer 232 views
1 answer 205 views
...