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

String

Syntax

Use gFormatNumbers.pkg

 

(FormatCurrency( {nVar}, {iPoints} ))

Where:

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

 

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 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.

Notes

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