Common:Convert Variables to Numbers
From AgileApps Support Wiki
Revision as of 00:35, 16 November 2013 by imported>Aeric
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 to a number that can be used in calculations:
- <syntaxhighlight lang="html4strict" enclose="div">
- set($n = 0.00)
- set($s = $YourObject.currency_field.substring(2) )
- set($n = $n.parseDouble($s)
</syntaxhighlight> 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.