I'm getting an error while trying to format a string number:
Argument type 'String' does not match the type of the format specifier '%.2f'.
The String is created by:
String cost = Double.parseDouble((Double.parseDouble(".04") * aLONGTYPEnumber * 24));
River
9,20115 gold badges57 silver badges69 bronze badges
2 Answers 2
The problem is you're trying to print a String using a double specifier (%.2f).
Using:
System.out.printf("%.2f", d);
requires that d is a double or Double, while your cost is a String.
Try it with:
double cost = Double.parseDouble(".04") * aLONGTYPEnumber * 24;
and it should work
answered May 11, 2017 at 2:56
River
9,20115 gold badges57 silver badges69 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
ter
Thank You so much it worked. I don't know what i was thinking.
You can format your string like:
NumberFormat formatter = new DecimalFormat("#0.00");
System.out.println(formatter.format((Double.parseDouble(".04") * aLONGTYPEnumber * 24)));
answered May 11, 2017 at 2:52
Kaushal28
5,5837 gold badges47 silver badges79 bronze badges
Comments
lang-java
doubledata