傳回格式化成百分比的運算式 (也就是乘以 100),並加上結尾的 % 字元。
命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)
語法
'宣告
Public Shared Function FormatPercent ( _
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.FormatPercent(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigits)
public static string FormatPercent (
Object Expression,
[OptionalAttribute] int NumDigitsAfterDecimal,
[OptionalAttribute] TriState IncludeLeadingDigit,
[OptionalAttribute] TriState UseParensForNegativeNumbers,
[OptionalAttribute] TriState GroupDigits
)
public:
static String^ FormatPercent (
Object^ Expression,
[OptionalAttribute] int NumDigitsAfterDecimal,
[OptionalAttribute] TriState IncludeLeadingDigit,
[OptionalAttribute] TriState UseParensForNegativeNumbers,
[OptionalAttribute] TriState GroupDigits
)
public static String FormatPercent (
Object Expression,
/** @attribute OptionalAttribute() */ int NumDigitsAfterDecimal,
/** @attribute OptionalAttribute() */ TriState IncludeLeadingDigit,
/** @attribute OptionalAttribute() */ TriState UseParensForNegativeNumbers,
/** @attribute OptionalAttribute() */ TriState GroupDigits
)
public static function FormatPercent (
Expression : Object,
NumDigitsAfterDecimal : int,
IncludeLeadingDigit : TriState,
UseParensForNegativeNumbers : TriState,
GroupDigits : TriState
) : String
參數
- Expression
必要項。要格式化的運算式。
- NumDigitsAfterDecimal
選擇項。數值,表示小數點右邊要顯示多少位。預設值為 –1,表示使用地區設定。
- IncludeLeadingDigit
選擇項。TriState 常數,指出是否要對小數值顯示前置 0 字元。請參閱值的「設定」。
- UseParensForNegativeNumbers
選擇項。TriState 常數,指出是否要將負數值放在括號內。請參閱值的「設定」。
- GroupDigits
選擇項。TriState 常數,指出是否使用地區設定中指定之群組分隔符號將數字分組。請參閱值的「設定」。
傳回值
傳回格式化成百分比的運算式 (也就是乘以 100),並加上結尾的 % 字元。
備註
如需詳細資訊,請參閱 Visual Basic 的主題 FormatPercent 函式 (Visual Basic)。
當省略了一或多個選擇性引數時,地區設定會提供省略的引數值。
注意事項 |
|---|
所有的設定資訊都是來自於應用程式的地區設定。根據預設,這會是控制台中設定的地區設定。但是,可以使用 .NET Framework,以程式方式加以變更。 |
IncludeLeadingDigit、UseParensForNegativeNumbers 和 GroupDigits 引數會具有下列設定。
常數 |
說明 |
|---|---|
TriState.True |
True |
TriState.False |
False |
TriState.Default |
電腦的地區設定 |
範例
這個範例將說明 FormatPercent 函式的用法。
Dim TestNumber As Single = 0.76
' Returns "76.00%".
Dim TestString As String = FormatPercent(TestNumber)
平台
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 命名空間
InvalidCastException
其他資源
FormatPercent 函式 (Visual Basic)
字串操作摘要
FormatCurrency 函式 (Visual Basic)
FormatDateTime 函式 (Visual Basic)
FormatNumber 函式 (Visual Basic)
Tristate 列舉型別
注意事項