Common:Convert Variables to Numbers
From LongJump Support Wiki
When you want to do calculations on a currency field in Velocity, you need to create a number from the currency strings delivered by the platform. That string has the form $ 24.95. The following code converts it into a number:
#set($n = 0.00) #set($s = $YourObject.currency_field.substring(2) ) #set($n = $n.parseDouble($s)
where:
- $n = 0.00 creates an instance of the double-precision float class (Double)
- $YourObject.currency_field.substring(2) removes the first two characters from the currency string. (The $ sign and the space that follows it.)
- parseDouble($s) converts the resulting string into a double-precision float--a number that can be used in calculations.