Maria Georgali Maria Georgali - 1 year ago 62
Java Question

Why I cannot format a double number in Android

I do a calculation between an integer and double and I get a number of 2.3333 and I use the following


to format it but I get an error of

java.util.IllegalFormatConversionException: %f can't format java.lang.String arguments


The problem is that ".2f" expects a double but you're giving it a String.

Just remove the String.valueOf() and it should work. Like this:

txtList.get(code-1).setText(String.format("%.2f", FinalPPP));