集册 Java实例教程 将字符串转换为双精度示例

将字符串转换为双精度示例

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

774
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将字符串转换为双精度示例

 

public class Main {

 
 /*
 来 自*
  时 代 J a v a
 */

  public static void main(String[] args) {

    //1. Construct Double using constructor.

    Double dObj1 = new Double("100.564");

    System.out.println(dObj1);

   

    //2. Use valueOf method of Double class. This method is static.

    String str1 = "100.476";

    Double dObj2 = Double.valueOf(str1);

    System.out.println(dObj2);

   

    /*

    To convert a String object to a double primitive value parseDouble method

    of Double class. 

    */

    String str2 = 
展开阅读全文