集册 Java实例教程 将Double转换为数字原始数据类型

将Double转换为数字原始数据类型

欢马劈雪     最近更新时间:2020-01-02 10:19:05

616
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将Double转换为数字原始数据类型
//来 自 n o w j a v a . c o m - 时代Java

public class Main {

 

  public static void main(String[] args) {

 

    Double dObj = new Double("10.50");

    //use byteValue method of Double class to convert it into byte type.

    byte b = dObj.byteValue();

    System.out.println(b);

   

    //use shortValue method of Double class to convert it into short type.

    short s = dObj.shortValue();

    System.out.println(s);
    /* 
    *来 自
     nowjava.com - 时  代  Java
    */

   

    //use intValue method of Double class to convert it into int type.

    int i = dObj.intValue();

    System.out.println(i);

   

    //use floatValue method of Double class to convert it into float type.

    float f = dObj.floatValue();

    System.out.println(f);
展开阅读全文