CrimsonKing CrimsonKing - 4 months ago 8
Java Question

Play2 Framework Float Format in Template

I got a little Problem with a Float Value in a Play Template. I wrote this code

@String.format("%.2f",session.get("product."+product.id.toString).toFloat*product.vkBrutto)


and I got this error:
Overloaded method value [format] cannot be applied to (String, Float)

I alredy tried other ways, but it wasn't successfull.
I'm searching for a possibility to get an output like this: 2,30
Maybe someone can help me,
thx

m-z m-z
Answer

That is not the correct usage for String.format. format must be called on the instance of a String, which contains the formatting.

Example:

"%.2f".format(2.19387474)

returns "2.19".

You'll want something like this:

@{"%.2f".format(session.get("product."+product.id.toString).toFloat*product.vkBrutto)}