开发者

String format in java?

开发者 https://www.devze.com 2023-01-09 05:58 出处:网络
Input String: 115.0000 Output St开发者_开发知识库ring should be like: 115.00 i used this code: String.format(\"%.2f\",\"115.0000\");

Input String: 115.0000

Output St开发者_开发知识库ring should be like: 115.00

i used this code:

String.format("%.2f","115.0000");

i got IllegalArgumentException. What can i do now?


You're submitting a string, but telling it to expect a floating point value. Remove the quotes around the number (second parameter).


String.format("%.2f", Double.parseDouble("115.0000"));
0

精彩评论

暂无评论...
验证码 换一张
取 消