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

定义

返回格式化为数字的表达式。Returns an expression formatted as a number.

public static string FormatNumber (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 FormatNumber : obj * int * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState -> string
Public Function FormatNumber (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 are displayed to the right of the decimal. 默认值为 -1,指示使用了计算机的区域设置。The default value is -1, which indicates that the computer's regional settings are used.

IncludeLeadingDigit
TriState

可选。Optional. TriState 常量,指示对于小数值是否显示前导零。TriState constant that indicates whether a leading 0 is displayed for fractional values. 请参阅“设置”,以获取值。See "Settings" for values.

UseParensForNegativeNumbers
TriState

可选。Optional. TriState 常量,指示是否用括号将负值括起来。TriState constant that indicates whether 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.

返回

格式化为数字的表达式。An expression formatted as a number.

异常

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

示例

此示例演示 FormatNumber 函数。This example demonstrates the FormatNumber function.

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

注解

如果省略了一个或多个可选参数,则由区域设置提供省略参数的值。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.UseDefault 计算机的区域设置The computer's regional settings

适用于

另请参阅