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: How do I manipulate real numbers?
Date Thu, 01 Mar 2001 17:34:28 GMT
Gustavo De Simone wrote:
> 
> Hi ,
> As you can see my question is if there any way to manipulate double numbers
> in the templates of veocity or if we shoul resolve that before calling to
> velocity templates.
> 
> I tried something like
> 
> $foo=$number1*$number2  where number1 and number2 were double numbers
> 
> and aomething like this:
> 
> $foo=$number*5.0                and "5.0" wasn't recognized as a number.

Velocity's math support is limited to integer mathematics.

Your best solution would be to either do the math before and place the
values in the context, or if you can't, make a little tool and place
that in the context :

public class MathTool
{
   public float mul( float arg1, float arg2 )
   {
	return arg1 * arg2;
   }

   etc
}

and use it as 

context.put("mathtool", new MathTool() );

in the template

#set($foo = $mathtool.mul( $number 5.0 ) )

(I just typed the above in - no guarantees :)

geir


-- 
Geir Magnusson Jr.                               geirm@optonline.com
Developing for the web?  See http://jakarta.apache.org/velocity/

Mime
View raw message