Question

I have a Stripes JSP with a <stripes:form> tag etc. I have a line like the following one:

<span class='amount'>
    <fmt:formatNumber value="${MyJavaClass.amount}" type="number"/>
</span>

I know this is working fine in combination with the corresponding Stripes Action Bean.

Now I want to format that "amount" variable in a different way, i.e. being sure that at least 2 decimals are used. For example:

199.1 becomes 199.10 362.44 remains 362.44

I thought that adding a formatPattern="decimal" would have been enough, according to Stripes documentation. Please note that I want to keep the "number" format type, I do not want to change it to be a currency type. Actually I am experiencing errors like the following one:

org.apache.jasper.JasperException: /MyJSPPath/MyJSP.jsp(19,6) Attribute formatPattern invalid for tag formatNumber according to TLD

How can I fix it?

Was it helpful?

Solution

I fixed it setting properly the pattern parameter.

<fmt:formatNumber value="${MyJavaClass.amount}" type="number" pattern="#.00"/>

This was not enough:

<fmt:formatNumber value="${MyJavaClass.amount}" type="number" maxFractionDigits="2"/>

The issue related to only one digit was still there (i.e. "199.3" was still "199.3", rather than "199.30")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top