I have a bean with BigDecimal field defined as
@Digits(integer=3, fraction=2)
@NumberFormat(style=Style.NUMBER)
private BigDecimal vatRate = new BigDecimal(0.0f);
Formatting works well inside form (I use <mvc:annotation-driven />
) but when trying to populate table with values as
<td> ${c.vatRate} %</td>
I am getting value as 12.30000000000000000000000000000000 %
or 0E-32 %
.
I have tried also to use <fmt:formatNumber/>
but I got an exception
In <formatNumber>, value attribute can not be parsed into java.lang.Number: " 0E-32"
Right now it comes to me only solution with special String getter for my bean that will provide formatted value. But is there any "nice" solution in presentation layer (ideally honouring @Digits annotation?)
Accidentally I have found following answer that solved my problem:
<td> <spring:eval expression="c.vatRate"/> %</td>