velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Kaufman" <>
Subject RE: comparing monetary value
Date Tue, 15 Oct 2002 17:44:55 GMT
> On Tuesday 15 October 2002 05:09 pm, Bill Kaufman wrote:
> > > 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.
> >
> > There's another solution I haven't noticed mentioned: Don't use
> > floating-point numbers.
> Bill, you seem to be saying that the solution to Velocity's 
> lack of floating 
> point numbers is not to use floating point numbers.

No (or, that wasn't my intention).  I'm saying instead that floating-point numbers aren't
well suited to monetary amounts, because of things like round-off errors and tricky comparisons
involving epsilons.

> In FreeMarker, we use java.math.BigDecimal by default, which 
> actually, in a sense, does what you're proposing.

Yup, BigDecimal would be the right way to go for monetary units.  But it may be overly complicated,
at least in Velocity today.

> Yeah, well, this is the thing. There are different number and 
> currency display 
> conventions in different locales. Just for starters, the 
> decimal separator in 
> some locales is a period (full stop) and in others is the 
> comma.

That part, at least, can be dealt with generically in Java, using java.text.NumberFormat.getInstance()
(not getCurrencyInstance()).  I don't know of any locale which displays monetary amount in
a different format from other numeric values (though I wouldn't rule it out).

(Now that I think of it, I suspect there should be a nice way to integrate Java formats into

                                                      -- Bill K.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message