FormatNumber Method

Strings.FormatNumber Method

Returns an expression formatted as a number.

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

Public Shared Function FormatNumber ( _
	Expression As Object, _
	NumDigitsAfterDecimal As Integer, _
	IncludeLeadingDigit As TriState, _
	UseParensForNegativeNumbers As TriState, _
	GroupDigits As TriState _
) As String
Dim Expression As Object 
Dim NumDigitsAfterDecimal As Integer 
Dim IncludeLeadingDigit As TriState 
Dim UseParensForNegativeNumbers As TriState 
Dim GroupDigits As TriState 
Dim returnValue As String 

returnValue = Strings.FormatNumber(Expression, _
	NumDigitsAfterDecimal, IncludeLeadingDigit, _
	UseParensForNegativeNumbers, GroupDigits)


Type: System.Object

Required. Expression to be formatted.

Type: System.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.

Type: Microsoft.VisualBasic.TriState

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

Type: Microsoft.VisualBasic.TriState

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

Type: Microsoft.VisualBasic.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.

Return Value

Type: System.String
Returns an expression formatted as a number.

For more detailed information, see the Visual Basic topic FormatNumber Function (Visual Basic).

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


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.








The computer's regional settings

This example demonstrates the FormatNumber function.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

© 2015 Microsoft