AgileApps Support Wiki Pre Release

Common:Convert Variables to Numbers

From AgileApps Support Wiki
Revision as of 19:53, 24 February 2012 by imported>Aeric (Created page with "<noinclude>__NOINDEX__</noinclude>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 platfor…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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:

<syntaxhighlight lang="html4strict" enclose="div">
  1. set($n = 0.00)
  2. set($s = $YourObject.currency_field.substring(2) )
  3. 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.