The FormatNumber Function

by Peter Tuffin on July 20, 2010

in User Reference

Post image for The FormatNumber Function

The FormatNumber function will take a numeric value and format it in various ways, as controlled by a pattern string.

Here follow some examples:

<<FormatNumber(age,"0.0")>>
<<FormatNumber(amount)>>
<<FormatNumber(price,'R#,0.00','ZA')>>
<<FormatNumber(balance,"#0.00;(#0.00)")>>
<<FormatNumber(IDNumber, "000000-0000-000")>>

  • Where the value of ‘age’ is 100, the result will be 100.0.
  • Where ‘amount’ is 9876, the result will be 9,876.00 (the default format).
  • Where the value of ‘price’ is 123456, the result will be R123 456,00. Note that the decimal format code “ZA” is required to indicate that the decimal point and thousands separator should be according to official South African format (as required, for example, by the South African Deeds Registry). Note also that the decimal format code “EU” will format the number according to European decimal rules, that is a full stop as the thousands separator and a comma as the decimal point.
  • Where ‘balance’ is 123456.78 the result is 123,456.78
  • Where ‘balance’ is -123456.78 the result will be (123,456.78).
  • Where ‘IDNumber’ is 4811145001080 the result will be 481114-5001-080.

Please also see the article The RenderAsNumeric function which shows how to make sure that the value typed in by a user can be made to be numeric regardless of the format in which they enter the value.

Note that the parameters of formatting functions (as against those of layout commands) must be enclosed in single or double quotes, unless their value is contained in a data element, in which case the data element name is not enclosed in quotes. In other words, it is those quotes, or their absence, that lets XpressDox know you want a formatting parameter as typed in the command, or as extracted from the data set, respectively. More extensive coverage is given in Notes on XpressDox syntax and also in Commands and Functions

Bookmark and Share

Related posts

Leave a Comment

Please remember your comments are subject to our comment rules.

Previous post:

Next post: