FormatPercent [VBA]
Returns a string with a number formatting applied to a numeric expression. A percent sign is appended to the returned string.
Tato konstanta, funkce nebo objekt se povoluje příkazem Option VBASupport 1, který je umístěn v modulu před spustitelným programem.
FormatPercent( expression, [numDigitsAfterDecimal As Integer], [includeLeadingDigit As Integer], _
[useParensForNegativeNumbers As Integer], [groupDigits As Integer] ) As String
String
expression: Required. A numeric expression to be formatted. If expression is a string, then the decimal and thousands separator need to be localized.
numDigitsAfterDecimal: Nepovinné. Číselná hodnota určující počet číslic, který se má zobrazit za desetinnou čárkou. Je-li vynecháno, výchozí hodnotou je -1, což znamená, že by se mělo použít národní nastavení uživatelského rozhraní.
includeLeadingDigit: Nepovinné. Hodnota výčtu vbTriState určující, zda se mají zobrazovat úvodní nuly.
-
vbTrue nebo -1: Úvodní nuly se zobrazí.
-
vbFalse nebo 0: Úvodní nuly se nezobrazí.
-
vbUseDefault or -2: Use the user interface locale settings. This is the default when omitted.
useParensForNegativeNumbers: Nepovinné. Hodnota výčtu vbTriState, která určuje, zda se mají záporná čísla zobrazovat v závorkách.
-
vbTrue nebo -1: Pro záporná čísla se použijí závorky.
-
vbFalse nebo 0: Závorky se nepoužijí.
-
vbUseDefault or -2: Same as vbFalse. This is the default when omitted.
groupDigits: Nepovinné. Hodnota výčtu vbTriState, která určuje, zda se mají číslice seskupovat (do tisíců apod.) s využitím oddělovače podle místního nastavení systému.
-
vbTrue nebo -1: Číslice budou členěny.
-
vbFalse nebo 0: Číslice nebudou členěny.
-
vbUseDefault or -2: Same as vbFalse. This is the default when omitted.
13 Datové typy nesouhlasí
Sub TestFormatNumber
Const UseComputerRegionalSettings = -1
MsgBox FormatPercent(12.2, NumDigitsAfterDecimal:=2) ' 1220.00% if selected user interface is english
MsgBox FormatPercent("-,2", 2, IncludeLeadingDigit:=vbTrue) ' -20,00% if french user interface
MsgBox FormatPercent("-0.2", 2) ' -20.00% for en-US, -0,00 for fr-CA, de-AT or pt-BR
MsgBox FormatPercent(-0.2, UseComputerRegionalSettings, UseParensForNegativeNumbers:=vbTrue) ' (20,00)% if pt-BR
MsgBox FormatPercent("-0,2", UseComputerRegionalSettings, vbUseDefault, vbTrue) ' (20,00)% if german
MsgBox FormatPercent("-12345678", -1, vbUseDefault, vbUseDefault, GroupDigits:=vbTrue) ' -1 234 567 800,00% for fr-BE
End Sub