Mat�as said:
> On Wednesday, March 12, 2003, at 04:50  PM, Nathan Bubna wrote:
> > if people are relying on  #set( $foo = 5 / 2 )  to make "$foo" == '2',
> > then
> > chances are they're doing not-very-proper-designer-ish things to begin
> > with.
> > even if it's legit stuff, it means that they should be savy enough to
> > repair
> > their templates when upgrading to 1.5 (assuming we properly warn of
> > this).
>
> What would be the way to repair that? Either VTL incorporates an
> integer division operator, or a double-to-integer conversion operator;
> otherwise integer division would be lost without a chance to recover it.

#set( $foo = 5 / 2 )
$foo.intValue()  :-)

or there's the classic Use-A-Tool (tm) response...

or even better...  they could move the suspect math (integer division) out
of their view layer!

> Also, beware of the differences in formatting between (new
> Integer(2)).toString() and (new Double(2)).toString(). What would we
> see when we do something like:
>
> #set($tot = $dogs.count() + $cants.count())
> <p>There are $tot pets in the store</p>
>
> (Hint: the answer is *not* "There are 15.0 pets in the store").

my suggestion to eschew messing with the various numeric types explicitly in
templates was NOT a suggestion to "always return Doubles."

i think the most intuitive behavior is simply to return a whole number when
the result of an operation (+,-,*, /, or %) is a whole number or a floating
point when the operation doesn't result in a whole.

if a designer really, really wants to be sure of double or integer output,
they can just tag .doubleValue() or .intValue() to their results.

if they want to get really fancy with 'rithmetic or rounding or formatting,
then it's time they used a tool (like velocity-tools' MathTool).  Velocity
isn't gonna support that stuff in the core.

Nathan Bubna
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to