共用方式為


Strings.FormatCurrency 方法

使用 [系統] 控制台中定義的貨幣符號,傳回格式化成貨幣值的運算式。

命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)

語法

'宣告
Public Shared Function FormatCurrency ( _
    Expression As Object, _
    <OptionalAttribute> Optional NumDigitsAfterDecimal As Integer = -1, _
    <OptionalAttribute> Optional IncludeLeadingDigit As TriState = TriState.UseDefault, _
    <OptionalAttribute> Optional UseParensForNegativeNumbers As TriState = TriState.UseDefault, _
    <OptionalAttribute> Optional GroupDigits As TriState = TriState.UseDefault _
) As String
'用途
Dim Expression As Object
Dim NumDigitsAfterDecimal As Integer
Dim IncludeLeadingDigit As TriState
Dim UseParensForNegativeNumbers As TriState
Dim GroupDigits As TriState
Dim returnValue As String

returnValue = Strings.FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigits)
public static string FormatCurrency (
    Object Expression,
    [OptionalAttribute] int NumDigitsAfterDecimal,
    [OptionalAttribute] TriState IncludeLeadingDigit,
    [OptionalAttribute] TriState UseParensForNegativeNumbers,
    [OptionalAttribute] TriState GroupDigits
)
public:
static String^ FormatCurrency (
    Object^ Expression, 
    [OptionalAttribute] int NumDigitsAfterDecimal, 
    [OptionalAttribute] TriState IncludeLeadingDigit, 
    [OptionalAttribute] TriState UseParensForNegativeNumbers, 
    [OptionalAttribute] TriState GroupDigits
)
public static String FormatCurrency (
    Object Expression, 
    /** @attribute OptionalAttribute() */ int NumDigitsAfterDecimal, 
    /** @attribute OptionalAttribute() */ TriState IncludeLeadingDigit, 
    /** @attribute OptionalAttribute() */ TriState UseParensForNegativeNumbers, 
    /** @attribute OptionalAttribute() */ TriState GroupDigits
)
public static function FormatCurrency (
    Expression : Object, 
    NumDigitsAfterDecimal : int, 
    IncludeLeadingDigit : TriState, 
    UseParensForNegativeNumbers : TriState, 
    GroupDigits : TriState
) : String

參數

  • Expression
    必要項。要格式化的運算式。
  • NumDigitsAfterDecimal
    選擇項。數值,表示小數點右邊要顯示多少位。預設值為 –1,表示要使用電腦的地區設定。
  • IncludeLeadingDigit
    選擇項。TriState 列舉型別,指出是否要對小數值顯示前置 0 字元。請參閱值的「設定」。
  • UseParensForNegativeNumbers
    選擇項。TriState 列舉型別,指出是否要將負數值放在括號內。請參閱值的「設定」。
  • GroupDigits
    選擇項。TriState 列舉型別,指出是否使用電腦的地區設定中指定之群組分隔符號將數字分組。請參閱值的「設定」。

傳回值

使用 [系統] 控制台中定義的貨幣符號,傳回格式化成貨幣值的運算式。

備註

如需詳細資訊,請參閱 Visual Basic 的主題 FormatCurrency 函式 (Visual Basic)

當省略一或多個選擇性引數時,會改用電腦對應的地區設定值。

相對於貨幣值的貨幣符號之位置是由系統的地區設定所決定。

Note注意事項

所有的設定資訊都是來自於應用程式的地區設定。根據預設,這會是控制台中設定的地區設定。但是,可以使用 .NET Framework 來以程式方式加以變更,除了來自於 [Number] 索引標籤的前置0 字元除外。

IncludeLeadingDigit、UseParensForNegativeNumbers 和 GroupDigits 引數會採用下列 TriState 列舉值。

說明

TriState.True

True

TriState.False

False

TriState.UseDefault

電腦的地區設定

範例

下列範例將說明如何使用 FormatCurrency 函式。

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

平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0、1.0

請參閱

參考

Strings 類別
Strings 成員
Microsoft.VisualBasic 命名空間
ArgumentException
InvalidCastException

其他資源

FormatCurrency 函式 (Visual Basic)
字串操作摘要
FormatDateTime 函式 (Visual Basic)
FormatNumber 函式 (Visual Basic)
FormatPercent 函式 (Visual Basic)
Tristate 列舉型別