enable RoundingMode for number formats
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
In Java 1.6, setRoundingMode was added to DecimalFormat. FreeMarker should expose this as a setting in the Configuration/Environment so that the rounding mode can be adjusted for decimal formats (HALF_UP in our case).
This problem was discussed previously on the mailing list at http://www.nabble.com/Change-rounding-mode-td19990183.html and we just ran into it as well when a customer complained about a 2.5 being rounded down.
Yeah, surely a missing thing. But that's a feature request, not a bug -- moved it over.
As of 2.3.24 you can specify pretty much all
DecimalFormat
options in the pattern string, in the 3rd;
-separated section. For example, you can change the rounding mode to half-up:"0.###;; roundingMode=halfUp"
.Last edit: Dániel Dékány 2016-05-21