Converting string to double with dot [duplicate]

旧街凉风 提交于 2021-01-28 03:40:46

问题


I need to convert string value to double with dot. Here is simple code

double dValue=Double.parseDouble("999999999.99");
System.out.println(dValue);
output is: 9.9999999999E8

When i gave value like 10000 or 100000 it works. Help me to overcome this problem.


回答1:


You could use BigDecimal and toPlainString() for that.

BigDecimal dValue= new BigDecimal("999999999.99");  
System.out.println(dValue.toPlainString());

Output:

999999999.99



回答2:


You can use String.format

System.out.println(String.format("%.2f", dValue));


来源:https://stackoverflow.com/questions/36474338/converting-string-to-double-with-dot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!