简体   繁体   中英

String format in java?

Input String: 115.0000

Output String 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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM