velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <ge...@optonline.net>
Subject Re: comparing monetary value
Date Tue, 15 Oct 2002 14:55:19 GMT
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.)

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.

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... 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...


-- 
Geir Magnusson Jr. 
geirm@adeptra.com                                    +1-203-355-2219 (w)
Adeptra Inc.                                         +1-203-247-1713 (m)



--
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