FormatCurrency
See Also: Locale Formatting Functions, String Functions, SetNumberFormat, SetCurrencyFormat, FormatNumber, FormatValue
Purpose
The FormatCurrency function formats a number and returns it as a string. The formatting by default uses the locale currency 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 currency when not using a data entry object (DEO), such as dbForm or cWebForm.
Return Type
Syntax
Use gFormatNumbers.pkg
(FormatCurrency( {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: Uses points as defined by the local currency setting.
- -2: Allows 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 currency formatting uses your locale Regional Setting Properties for Currency.
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 SetCurrencyFormat message.
Move (FormatCurrency(nVar, 2)) to sString
Formatting with the locale Regional Setting Properties for Currency will yield different results since settings can vary on each computer.
For example:
Move (FormatCurrency(nNumber, 2)) to sString
This would result in DM123.222,22 and -DM123.222,22 with German settings, but $123,222.22 and -$123,222.22 with USA regional settings.
Notes
-
The
FormatCurrencyfunction is almost identical to theFormatNumberfunction. The reason for the two very similar functions is that one is used in conjunction with theSetCurrencyFormatmasking function and the other is used in conjunction with theSetNumberFormatmasking function. This allows us to have two masks available, one for masking numbers and one for masking currency. -
FormatCurrencyuses "$" as a replacement for the regional currency symbol. -
The
iPointsparameter is used to truncate the decimal portion; no rounding of the number occurs.
This example shows when to use the FormatCurrency and FormatNumber functions:
Procedure OnBody
Send WriteHtmlRowBegin
Send WriteHtmlCell (HtmlEncode(invt.Item_id)) 'align="left" '
Send WriteHtmlCell (HtmlEncode(Invt.Description)) 'align="left" '
Send WriteHtmlCell (FormatNumber(OrderDtl.Price, 2)) 'align="right" '
Send WriteHtmlCell (FormatNumber(OrderDtl.Qty_ordered, 0)) 'align="right" '
// displays extended price with currency symbol:
Send WriteHtmlCell (FormatCurrency(OrderDtl.Extended_Price, 2)) 'align="right" '
Send AddSubTotal 1 OrderDtl.Extended_Price
Send WriteHtmlRowEnd
End_Procedure
Procedure OnPageBottom
Number nTotal
Send WriteHtmlCell "" 'colspan="4" bgColor="Silver" '
Get SubTotal 1 to nTotal
Send WriteHtmlCell (FormatCurrency(nTotal, 2)) 'bgColor="Silver" align="right" '
Send WriteHtmlTableEnd
End_Procedure