Bewerken

Share via


Strings.FormatNumber(Object, Int32, TriState, TriState, TriState) Method

Definition

Returns an expression formatted as a number.

public static string FormatNumber (object? Expression, int NumDigitsAfterDecimal = -1, Microsoft.VisualBasic.TriState IncludeLeadingDigit = Microsoft.VisualBasic.TriState.UseDefault, Microsoft.VisualBasic.TriState UseParensForNegativeNumbers = Microsoft.VisualBasic.TriState.UseDefault, Microsoft.VisualBasic.TriState GroupDigits = Microsoft.VisualBasic.TriState.UseDefault);
public static string FormatNumber (object Expression, int NumDigitsAfterDecimal = -1, Microsoft.VisualBasic.TriState IncludeLeadingDigit = Microsoft.VisualBasic.TriState.UseDefault, Microsoft.VisualBasic.TriState UseParensForNegativeNumbers = Microsoft.VisualBasic.TriState.UseDefault, Microsoft.VisualBasic.TriState GroupDigits = Microsoft.VisualBasic.TriState.UseDefault);
static member FormatNumber : obj * int * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState -> string
Public Function FormatNumber (Expression As Object, Optional NumDigitsAfterDecimal As Integer = -1, Optional IncludeLeadingDigit As TriState = Microsoft.VisualBasic.TriState.UseDefault, Optional UseParensForNegativeNumbers As TriState = Microsoft.VisualBasic.TriState.UseDefault, Optional GroupDigits As TriState = Microsoft.VisualBasic.TriState.UseDefault) As String

Parameters

Expression
Object

Required. Expression to be formatted.

NumDigitsAfterDecimal
Int32

Optional. Numeric value indicating how many places are displayed to the right of the decimal. The default value is -1, which indicates that the computer's regional settings are used.

IncludeLeadingDigit
TriState

Optional. TriState constant that indicates whether a leading 0 is displayed for fractional values. See "Settings" for values.

UseParensForNegativeNumbers
TriState

Optional. TriState constant that indicates whether to place negative values within parentheses. See "Settings" for values.

GroupDigits
TriState

Optional. TriState constant that indicates whether or not numbers are grouped using the group delimiter specified in the locale settings. See "Settings" for values.

Returns

An expression formatted as a number.

Exceptions

Type is not numeric.

Examples

This example demonstrates the FormatNumber function.

Dim testNumber As Integer = 45600
' Returns "45,600.00".
Dim testString As String = FormatNumber(testNumber, 2, , , TriState.True)

Remarks

When one or more optional arguments are omitted the values for omitted arguments are provided by the locale settings.

Note

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.

The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments have the following settings.

Constant Description
TriState.True True
TriState.False False
TriState.UseDefault The computer's regional settings

Applies to

See also