Strings.FormatPercent Method

Returns an expression formatted as a percentage (that is, multiplied by 100) with a trailing % character.

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

public static string FormatPercent(
	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 to the right of the decimal are displayed. Default value is –1, which indicates that the locale settings are used.

IncludeLeadingDigit
Type: Microsoft.VisualBasic.TriState

Optional. TriState constant that indicates whether or not a leading zero displays for fractional values. See "Settings" for values.

UseParensForNegativeNumbers
Type: Microsoft.VisualBasic.TriState

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

GroupDigits
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 percentage (that is, multiplied by 100) with a trailing % character.

ExceptionCondition
InvalidCastException

Type is not numeric.

When one or more optional arguments are omitted, the values for omitted arguments are provided by the locale 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.

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

Constant

Description

TriState.True

True

TriState.False

False

TriState.Default

The computer's regional settings

This example illustrates the use of the FormatPercent function.

Dim TestNumber As Single = 0.76
' Returns "76.00%". 
Dim TestString As String = FormatPercent(TestNumber)

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft