See Also: Locale Formatting Functions, String Functions, SetNumberFormat, SetCurrencyFormat, FormatNumber, FormatValue
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.
Use gFormatNumbers.pkg
(FormatCurrency( {nVar}, {iPoints} ))
Where:
{nVar} ia 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 a defined by the local currency setting |
-2 |
Allow any number of points to the right of the decimal as needed |
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 give different results since settings can be different on each computer.
For example:
Move (FormatCurrency(nNumber, 2)) to sString
Would result with DM123.222,22 and -DM123.222,22 with German settings, but $123,222.22 and -$123,222.22 with USA regional settings.
The FormatCurrency function is almost identical to the FormatNumber function. The reason for the two very similar functions is that one is used in conjunction with the SetCurrencyFormat masking function and the other is used in conjunction with the SetNumberFormat masking function. This allows us to have two masks available, one for masking numbers and one for masking currency.
FormatCurrency uses "$" as a replacement for the regional currency symbol.
The iPoints parameter 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