q8DT2‖

5GSq4‖FormatPercent [VBA]

wE9n7‖Returns a string with a number formatting applied to a numeric expression. A percent sign is appended to the returned string.

warning

R9TFi‖This constant, function or object is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.


FVEx2‖Syntax:


      FormatPercent( expression, [numDigitsAfterDecimal As Integer], [includeLeadingDigit As Integer], _
          [useParensForNegativeNumbers As Integer], [groupDigits As Integer] ) As String
    

bBBqF‖Return type:

String

WADQ4‖Parameters:

JCPah‖expression: Required. A numeric expression to be formatted. If expression is a string, then the decimal and thousands separator need to be localized.

mD2xQ‖numDigitsAfterDecimal: Optional. A numeric value specifying the number of digits that should be displayed after the decimal. If omitted, it defaults to the value -1, meaning that the default settings for user interface locale should be used.

iFkar‖includeLeadingDigit: Optional. A vbTriState enumeration value, specifying whether a leading zero should be displayed for fractional values.

xEHZb‖useParensForNegativeNumbers: Optional. A vbTriState enumeration value specifying whether negative numbers should be encased in parenthesis.

pj4ES‖groupDigits: Optional. A vbTriState enumeration value specifying the number should be grouped (into thousands, etc.), using the group delimiter that is specified on the system's regional settings.

SEjHR‖Error codes:

13 Data type mismatch

EFSA4‖Example:


        Sub TestFormatNumber
          Const UseComputerRegionalSettings = -1

        DbBkG‖  MsgBox FormatPercent(12.2, NumDigitsAfterDecimal:=2) ' 1220.00% if selected user interface is english

        Z6UjG‖  MsgBox FormatPercent("-,2", 2, IncludeLeadingDigit:=vbTrue) ' -20,00% if french user interface

        bAAUF‖  MsgBox FormatPercent("-0.2", 2) ' -20.00% for en-US, -0,00 for fr-CA, de-AT or pt-BR

        HFTfd‖  MsgBox FormatPercent(-0.2, UseComputerRegionalSettings, UseParensForNegativeNumbers:=vbTrue) ' (20,00)% if pt-BR

        PAwQL‖  MsgBox FormatPercent("-0,2", UseComputerRegionalSettings, vbUseDefault, vbTrue) ' (20,00)% if german

        A7ZyN‖  MsgBox FormatPercent("-12345678", -1, vbUseDefault, vbUseDefault, GroupDigits:=vbTrue) ' -1 234 567 800,00% for fr-BE

        End Sub