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

定义

返回一个格式为货币值的表达式,该货币值使用系统控制面板中定义的货币符号。Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.

public static string FormatCurrency (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 FormatCurrency : obj * int * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState * Microsoft.VisualBasic.TriState -> string
Public Function FormatCurrency (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,指示使用了计算机的区域设置。Default value is -1, which indicates that the computer's regional settings are used.

IncludeLeadingDigit
TriState

可选。Optional. TriState 枚举,指示对于小数值是否显示前导零。TriState enumeration that indicates whether or not a leading zero is displayed for fractional values. 请参见值的“备注”。See "Remarks" for values.

UseParensForNegativeNumbers
TriState

可选。Optional. TriState 枚举,指示是否用括号将负值括起来。TriState enumeration that indicates whether or not to place negative values within parentheses. 请参见值的“备注”。See "Remarks" for values.

GroupDigits
TriState

可选。Optional. TriState 枚举,指示是否用计算机区域设置中指定的组分隔符对数字进行分组。TriState enumeration that indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings. 请参见值的“备注”。See "Remarks" for values.

返回

一个格式为货币值的表达式,该货币值使用系统控制面板中定义的货币符号。An expression formatted as a currency value using the currency symbol defined in the system control panel.

异常

小数点后的数字位数大于 99。Number of digits after decimal point is greater than 99.

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

示例

下面的示例阐释了 FormatCurrency 函数的用法。The following example illustrates the use of the FormatCurrency function.

Dim testDebt As Double = -4456.43
Dim testString As String
' Returns "($4,456.43)".
testString = FormatCurrency(testDebt, , , TriState.True, TriState.True)

注解

省略一个或多个可选参数时,将改用计算机的匹配区域设置值。When one or more optional arguments are omitted, the computer's matching regional-settings values are used instead.

货币符号相对于货币值的位置由系统的区域设置确定。The position of the currency symbol relative to the currency value is determined by the system's regional 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 以编程方式更改它,但不带前导零的情况除外,它来自 Number 选项卡。However, it may be changed programmatically by using the .NET Framework, except leading zero, which comes from the Number tab.

@No__t,`UseParensForNegativeNumbers` 和 GroupDigits 参数采用以下三态枚举值。The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments take the following TriState enumeration values.

Value 说明Description
TriState.True TrueTrue
TriState.False FalseFalse
TriState.UseDefault 计算机的区域设置The computer's regional settings

适用于

另请参阅