XpressDox Help Center

Use Google To Find Help Fast, e.g. xpressdox choosefromlist


Press Getting Started in the XpressDox toolbar for basic template development
Watch the tutorial videos
View command help from list of commands
Press F1 for help on a command in the Command Editor
Email support@xpressdox.com for assistance

The CentsToCurrency and CurrencyToCents Functions


The CentsToCurrency and CurrencyToCents Functions

Probably the best way to perform arithmetic on money values in XpressDox is to reduce all currency to integer values (e.g. Dollars to cents, Pounds to pence, etc), perform the arithmetic and then render the value back to the currency value.  The aim is to reduce the possibility of rounding errors creeping in, and also to overcome at least some of the issues covered in the article Handling calculations and Regional Settings in XpressDox.

Suppose you have retrieved a value of $1234.56 from a database and this is in the data element Price.  The snippet

The price in cents is «CurrencyToCents(Price)»

would render as

The price in cents is 123456

If some arithmetic were done on this, for example:

«SetV('Total',0)»
«SetV('PriceInCents',CurrencyToCents(Price))»
«IncrementV('Total',GetV('PriceInCents'))»
[repeated a few times in the real world]

Then the result could be rendered back in Dollars (or Pounds or whatever) with:

«CentsToCurrency(GetV('Total'),'#,0.00')»

or

«CentsToCurrency(GetV('Total'),'#,0.00','fr')»

In other words, it is not necessary to first convert the cents to currency and then apply FormatNumber – those two operations can be combined in one as above.

These two functions are available in XpressDox Version 4.3.8 and higher.

Leave a Reply