Convert String to double in Java

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

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

14条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 06:26

    Citing the quote from Robertiano above again - because this is by far the most versatile and localization adaptive version. It deserves a full post!

    Another option:

    DecimalFormat df = new DecimalFormat(); 
    DecimalFormatSymbols sfs = new DecimalFormatSymbols();
    sfs.setDecimalSeparator(','); 
    df.setDecimalFormatSymbols(sfs);
    double d = df.parse(number).doubleValue();
    

提交回复
热议问题