Muokkaa

Jaa


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);
static member FormatPercent : obj * int * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState -> string
Public Function FormatPercent (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 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

See also