Partager via


Strings.FormatCurrency Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

Syntax

'Declaration
Public Shared Function FormatCurrency ( _
    Expression As Object, _
    NumDigitsAfterDecimal As Integer, _
    IncludeLeadingDigit As TriState, _
    UseParensForNegativeNumbers As TriState, _
    GroupDigits As TriState _
) As String
public static string FormatCurrency(
    Object Expression,
    int NumDigitsAfterDecimal,
    TriState IncludeLeadingDigit,
    TriState UseParensForNegativeNumbers,
    TriState GroupDigits
)

Parameters

  • Expression
    Type: System.Object
    Required. Expression to be formatted.
  • NumDigitsAfterDecimal
    Type: System.Int32
    Optional. Numeric value indicating how many places are displayed to the right of the decimal. Default value is –1, which indicates that the computer's regional settings are used.
  • IncludeLeadingDigit
    Type: Microsoft.VisualBasic.TriState
    Optional. TriState enumeration that indicates whether or not a leading zero is displayed for fractional values. See "Settings" for values.
  • UseParensForNegativeNumbers
    Type: Microsoft.VisualBasic.TriState
    Optional. TriState enumeration that indicates whether or not to place negative values within parentheses. See "Settings" for values.
  • GroupDigits
    Type: Microsoft.VisualBasic.TriState
    Optional. TriState enumeration that indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings. See "Settings" for values.

Return Value

Type: System.String
Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.

Remarks

When one or more optional arguments are omitted, the computer's matching regional-settings values are used instead.

The position of the currency symbol relative to the currency value is determined by the system's regional settings.

NoteNote:

All settings information comes from the locale of the application. By default, that will be the locale set in the control panel. However, it may be changed programmatically by using the .NET Framework, except leading zero, which comes from the Number tab.

The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments take the following TriState enumeration values.

Value

Description

TriState.True

True

TriState.False

False

TriState.UseDefault

The computer's regional settings

Examples

The following example illustrates the use of the FormatCurrency function.

Dim TestDebt As Double = -4456.43
Dim TestString As String
' Returns "($4,456.43)".
TestString = FormatCurrency(TestDebt, , , TriState.True, TriState.True)

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.