FormatNumber
See Also: Locale Formatting Functions, String Functions, SetNumberFormat, SetCurrencyFormat, FormatCurrency, FormatValue
Purpose
The FormatNumber function formats a number and returns it as a string. The formatting by default uses the locale number settings of your machine, and the iPoints parameter determines the number of digits to the right of the decimal.
This can be used to format a string containing numbers when not using a data entry object (DEO), such as dbForm or cWebForm.
Return Type
Syntax
Use gFormatNumbers.pkg
(FormatNumber( {nVar}, {iPoints} ))
Where:
- {nVar} is a value of type number.
- {iPoints} determines the formatting. Possible values for {iPoints}:
- 0 or Greater: Use the points as specified to limit the digits to the right of the decimal.
- -1: Use points as defined in the
SetNumberFormatmessage. - -2: Allow any number of points to the right of the decimal as needed.
What it Does
The formatting of the fractional portion is based on the iPoints parameter value. The rest of the number formatting uses your locale Regional Setting Properties for Numbers.
If you do not wish to use these default currency settings, you may customize a format string to use as the formatting mask by sending the SetNumberFormat message.
Move (FormatNumber(nVar, 2)) to sString
Formatting with the locale Regional Setting Properties for Numbers will yield different results since settings can vary on each computer.
For example:
Move (FormatNumber(nNumber, 2)) to sString
Would result in 123.222,22 and -123.222,22 with German settings, but 123,222.22 and -123,222.22 with USA regional settings.
Special Notes
-
The
FormatNumberfunction is almost identical to theFormatCurrencyfunction. The reason for the two very similar functions is that one is used in conjunction with theSetNumberFormatmasking function and the other is used in conjunction with theSetCurrencyFormatmasking function. This allows us to have two masks available, one for masking numbers and one for masking currency. -
FormatNumberuses "$" as a replacement for the regional currency symbol. -
The
iPointsparameter is used to truncate the decimal portion; no rounding of the number occurs.