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

Definition

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

public static string FormatPercent (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 FormatPercent (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);

Parameters

Expression
Object

Required. Expression to be formatted.

NumDigitsAfterDecimal
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
TriState

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

UseParensForNegativeNumbers
TriState

Optional. TriState constant that indicates whether or not 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 percentage (that is, multiplied by 100) with a trailing % character.

Exceptions

Type is not numeric.

Examples

This example illustrates the use of the FormatPercent function.

Dim testNumber As Single = 0.76
' Returns "76.00%".
Dim testString As String = FormatPercent(testNumber)

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.Default The computer's regional settings

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also