Strings.FormatPercent(Object, Int32, TriState, TriState, TriState) 方法

定义

返回以 % 字符结尾的百分比格式的表达式(即乘以 100)。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);
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

参数

Expression
Object

必需。Required. 要格式化的表达式。Expression to be formatted.

NumDigitsAfterDecimal
Int32

可选。Optional. 数字值,该值指示要显示小数点右侧的多少位。Numeric value indicating how many places to the right of the decimal are displayed. 默认值为 -1,指示使用了区域设置。Default value is -1, which indicates that the locale settings are used.

IncludeLeadingDigit
TriState

可选。Optional. TriState 常量,指示是否显示小数值前的零。TriState constant that indicates whether or not a leading zero displays for fractional values. 请参阅“设置”,以获取值。See "Settings" for values.

UseParensForNegativeNumbers
TriState

可选。Optional. TriState 常量,指示是否在括号内放入负值。TriState constant that indicates whether or not to place negative values within parentheses. 请参阅“设置”,以获取值。See "Settings" for values.

GroupDigits
TriState

可选。Optional. TriState 常量,指示是否使用区域设置中指定的组分隔符对数字进行分组。TriState constant that indicates whether or not numbers are grouped using the group delimiter specified in the locale settings. 请参阅“设置”,以获取值。See "Settings" for values.

返回

以 % 字符结尾的百分比格式(即乘以 100)的表达式。An expression formatted as a percentage (that is, multiplied by 100) with a trailing % character.

异常

不是数字类型。Type is not numeric.

示例

此示例演示如何使用 FormatPercent 函数。This example illustrates the use of the FormatPercent function.

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

注解

如果省略了一个或多个可选参数,则省略参数的值由区域设置提供。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. 但是,可以使用 .NET Framework 以编程方式对其进行更改。However, it may be changed programmatically by using the .NET Framework.

@No__t-0、`UseParensForNegativeNumbers` 和 GroupDigits 参数具有以下设置。The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments have the following settings.

返回的常量Constant 说明Description
TriState.True TrueTrue
TriState.False FalseFalse
TriState.Default 计算机的区域设置The computer's regional settings

适用于

另请参阅