velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Denis <j...@respublica.fr>
Subject Re: comparing monetary value
Date Wed, 16 Oct 2002 11:00:36 GMT

On Wednesday, October 16, 2002, at 08:44  am, Martin Jacobson wrote:

> 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.
>
>
> This thread, for all the heat it is generating, surely revolves 
> around the separation between business logic, and presentation. If 
> you think that a rigorous separation is a Good Thing, then there 
> seems, on the present evidence, to be no requirement for Velocity 
> to handle any numerical values other than integers. If, on the 
> other hand, you want to be able to manipulate, eg, monetary values 
> in the template, then 'vanilla' Velocity won't work for you.

Even without manipulating floating point values, it would be nice 
to have a _standard_ tool in Velocity to format integers as a 
currency.

E.g.
#set ($valueInCents = 249)
$currency.dollar(valueInCents)

-> $ 2.49


In fact it could even be done with a macro...

#macro (dollar $valueInCents)
#set( $dollars = $valueInCents / 100 )
#set( $cents1 = $valueInCents % 100 / 10 )
#set( $cents2 = $valueInCents % 10 )
$ ${dollars}.${cents1}${cents2}##
#end

#dollar(249)

-> $ 2.49


Sorry for thinking out loud... We don't really need a standard tool 
for currencies.

Is there a good place where to find Velocimacro libraries, so I 
don't have to invent things again?
Cheers,

-- Denis.


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