SoFunction
Updated on 2025-04-11

VBS tutorial: Functions - FormatPercent Function

FormatPercent function

Returns the expression, which has been formatted as a percentage trailing with the % symbol (multiply by 100 ).

FormatPercent(expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])

The syntax of the FormatPercent function has the following parameters:

parameter

Expression

Required option. The expression to be formatted.

NumDigitsAfterDecimal

Optional. Indicates the value of the number of digits displayed on the right side of the decimal point. The default value is -1, indicating that the computer's locale is used.

IncludeLeadingDigit

Optional. A three-state constant indicating whether the zero before the decimal point is displayed. For values, see the Settings section.

UseParensForNegativeNumbers

Optional. Tri-state constant indicating whether negative values ​​are placed in brackets. For values, see the Settings section.

GroupDigits

Optional. Tri-state constant indicating whether to group numbers using the number grouping symbol specified in the computer locale. For values, see the Settings section.

set up

The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits parameters can have the following values:

constant value describe
TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 Use the settings in the computer locale.

illustrate

When one or more optional parameters are omitted, the value of the omitted parameters is provided by the computer locale.

NoticeAll settings information are taken from the "digital" tag of the locale.

The following example usesFormatPercentFunction formats expressions as percentages:

Dim MyPercentMyPercent = FormatPercent(2/32) 'MyPercent Include 6.25%