Search code examples
javaspring-mvcfreemarkerbigdecimal

Forcing FreeMarker to always print BigDecimal value with decimal point


In a Spring MVC application using FreeMarker for rendering views, how do I force FreeMarker to always print BigDecimal values with decimal points?

For instance:

1000.12 -> 1000.12
1000    -> 1000.00

I tried

${value?string("0.##")}

This printed 1000.12 correctly as 1000.12 but 1000 still printed as 1000 instead of 1000.00.


Solution

  • Have you tried ${1000?string("0.00")}?

    If you need to round your numbers down use ((n * 100)?floor) / 100.0 expression