Re: Change rounding mode
Attila Szegedi <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I should probably also note that the rounding policy only applies for operations on BigInteger and BigDecimal numbers, and then only for division and for multiplication (when the scale of the multiplication product is higher than the value set by ArithmeticEngine.setMaxScale()). The default ArithmeticEngine is BigDecimal based, so all divisions and multiplications are subject to the rounding mode. Some people use a ConservativeArithmeticEngine that operates on Java finite-precision types and widens them without overflow as necessary (int->long- >BigInteger, float->double->BigDecimal etc.). If you use it, then rounding mode will only kick in when the values used in arithmetic operations can no longer fit in a long/double and become propagated to BigInteger/BigDecimal internally. Meaning, if you want to rigorously enforce the rounding mode, make sure you stick with the default BigDecimalArithmeticEngine. Attila. On Oct 15, 2008, at 12:53 PM, Attila Szegedi wrote: > Sure: > > freemarker.template.Configuration myConfig = ...; > myConfig > .getArithmeticEngine().setRoundingMode(BigDecimal.ROUND_HALF_UP); > > Attila. > > On Oct 15, 2008, at 9:23 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. >> >> 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=/