Re: Change rounding mode
David Cuenca <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I would like to change the formatting that freemarker uses to show a
Double with only two decimal positions (${x?string("0.##")}). I want
freemarker to round it with the half-up rule.
Daniel Dekany wrote:
Wednesday, October 15, 2008, 9:23:58 AM, David Cuenca wrote:
Hello,
I would like to know if there is an easy way to change freemarker's
default rounding mode. As the freemarker manual says:
"Following the financial and statistics practice, the rounding goes
according the so called half-even rule, which means rounding towards the
nearest ``neighbor'', unless both neighbors are equidistant, in which
case, it rounds towards the even neighbor..."
But I would like to use HALF_UP.
Out of curiosity, why?
Otherwise I don't think it's possible in FreeMarker, since it's number
formatting is what the Java platform provides, and DecimalFormat uses
half-even rounding, and it isn't configurable in this regard. That
said, you couldn't even do that in a Java program. So, blame the J2SE
API guys... ;)
Of course, you could write the function for this easily:
<#function n3 n>
<#return ((n*1000)?round/1000)?string>
</#function>
Does anybody know if it's configurable?
Thanks!
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user