velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Revusky <>
Subject Re: comparing monetary value
Date Tue, 15 Oct 2002 16:56:53 GMT
On Tuesday 15 October 2002 04:55 pm, Geir Magnusson Jr wrote:
> On 10/15/02 2:06 AM, "STham@thoughtworks.COM" <STham@thoughtworks.COM>
> wrote:
> > Hi,
> >
> >  I believed at the moment, all numbers are treated as Integer. Anyone
> > came across this problem of manipulating with money value before?
> >
> > Example :
> >
> > 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.
> Just to give some background (and this is another subject if much heated
> discussion)...
> The idea behind not having floating point number support is that it allows
> one to wander from the notion that Velocity templating is used for the view
> layer, and begin to do things that other parts of you program should be
> doing.
> So when you put something like 0.01 in a template, that should actually be
> data from your data model, like $maxAmount or the like.
> Now, currently velocity won't allow that - you can't play by the rule I
> just suggested and do somethinng like
>   #if ($someMoneyValye < $maxAmount)
>     ....
> Because < operates only on integers.  This is another exhibition of the
> initial idea that VTL features were for the designers (we had a huge fight
> about % IIRC, to give you an idea how strong some of the feelings were
> about this.)

Well, of course a templating language should be oriented towards the designers 
and other non-technical people. However, the idea that you have to be a 
programmer to need decimal numbers strikes me as rather far-fetched frankly.

I mean, presumably, designers are citizens who fill out their income tax every 
year, and in so doing, they use decimal numbers and four-function calculator 

> So to solve the problem, you would add a tool, some generic number
> comparison tool to do
>   #if ($myTool.lessThan($someValye, $maxAmount))
>      ...
> That is the solution we all do now.

Well, I suppose that's true if you don't include the people who have switched 
to FreeMarker (there are at least a couple I know of). Those people write:

<if someValue < maxAmount>


> My personal position on this has moved - I have been playing with allowing
> floating point *comparison* w/o allowing floating point literals in other
> Velocity-like systems I work on, keeping the idea that any such literal has
> to be data in the model (as I can't think of any reason why a designer
> would need it for calculating display-related values, like rows or
> columns... 

Well, I don't think you're trying very hard, frankly. Surely it's easy enough 
to come up with examples where a non-programmer would want to do some 
non-integer arithmetic in a template. For example, in Europe recently, there 
was this big move to the euro, the unified currency. As it happens, most 
people in the euro zone do not have a good intuitive feel for the euro and 
still reckon things in the old currency -- francs, deutsche marks, etcetera.

Imagine a simple app, a catalogue, where you display the price of things. The 
catalogue is in euros, of course. A non-technical manager points out that it 
would be better to show the amount in the superseded local currency in 

So, instead of simply having:

The price is: $price euros.

they want:

The price is: $price euros. (${price*6.556 FFR)

let's say for French francs in this example. What you seem to be implying is 
that the non-technical people who want to introduce this change should have 
to talk to the programmers so that they expose the constant in the template. 
For some reason, it is "bad" (TM) for them to write 6.556 literally in the 

(Of course, the same argument could be made for conversions between celsius 
and farenheit, kilometres and miles, and so on... Basically, these units of 
measure are just alternative ways of presenting the same canonical 
information and it's not clear why somebody working on the view level should 
not have the full discretion to do this stuff without the intervention of 

But what I don't understand about all of this is, what is the justification 
for letting people write a literal string or a literal integer but not a 
literal decimal number.

I mean, why would you support decimal numbers (in some hypothetical future 
version) and let people write:

#set $x=1

and NOT let them write:

#set $x=1.1

It just seems terribly non-orthogonal. Is there really any justification 
(either theoretical or pragmatic) for such a non-orthogonality?

I actually recall posing this question before and never receiving a response. 

> I guess in real graphics design you do fractional units of
> measure, but I suppose you wouldn't use Velocity for that anyway...).  The
> other Vel-like things I work on are not templating systems, but scripting
> environments where floating point comparisons are fully required, so maybe
> my thinking is getting 'polluted' by working in Vel-like scripting tools...

Well, my take on this is that your thinking is just getting "polluted" by 
actually having real-world problems to solve. You finally had to yield to the 
evidence and accept that decimal numbers are... err.... kinda useful 
sometimes... ;-)

Best Regards,

Jonathan Revusky
FreeMarker-Velocity comparison doc
Velocity->FreeMarker template conversion utility

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

View raw message