velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Kaufman" <BKauf...@zaplet.com>
Subject RE: comparing monetary value
Date Tue, 15 Oct 2002 15:09:19 GMT
> STham@thoughtworks.COM wrote:
> 
> >  Give a certain amount has to be less than a given value.
> >
> >   if ($someMoneyValue < 0.01) ???
> >
> >How do people normally handle money in velocity?? Thanks.
> 
> Apparently, they put some kind of custom "tool" in the context. This 
> strikes me as quite undesirable really, though it is a necessary 
> workaround due to VTL's lack of support for decimal numbers.

There's another solution I haven't noticed mentioned: Don't use floating-point numbers.

Instead, calculate everything as integers of the smallest unit (e.g., cents, or tenths of
cents).  Not only does this work better in Velocity, it's also exact and avoids round-off
errors.

Of course, this does have the problem that you'd have to somehow specify the units for every
currency you support (e.g., 100ths or 1000ths for US$, versus 1s for lira),...

                                                      -- Bill K.

--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message