Convert String to double in Java

后端 未结 14 1471
傲寒
傲寒 2020-11-22 05:52

How can I convert a String such as \"12.34\" to a double in Java?

相关标签:
14条回答
  • 2020-11-22 06:39

    There is another way too.

    Double temp = Double.valueOf(str);
    number = temp.doubleValue();
    

    Double is a class and "temp" is a variable. "number" is the final number you are looking for.

    0 讨论(0)
  • Try this, BigDecimal bdVal = new BigDecimal(str);

    If you want Double only then try Double d = Double.valueOf(str); System.out.println(String.format("%.3f", new BigDecimal(d)));

    0 讨论(0)
提交回复
热议问题