Method: FormatPercent for VBS
- Updated2024-09-12
- 1 minute(s) read
Methods > Method: FormatPercent for VBS
Method: FormatPercent for VBS
Formats a percentage value. To do this, the FormatPercent method multiplies the value by 100 and appends a % character.
vFormatPercent = Object.FormatPercent(expression, [NumDigitsAfterDecimal], [IncludeLeadingDigit], [UseParensForNegativeNumbers], [GroupDigits])
| Object | VBS Object with this method. You do not need to specify this object. |
| expression | Variant Specifies the expression to be formatted. |
| [NumDigitsAfterDecimal] | Variant Specifies the number of decimal places behind the decimal separator. If you do not specify a value, the FormatPercent method uses the value -1, which means that the method uses the regional settings of your computer. |
| [IncludeLeadingDigit] | Variant Specifies whether the FormatPercent method displays leading zeros. Valid values are vbTrue, vbFalse, and vbUseDefault. |
| [UseParensForNegativeNumbers] | Variant Specifies whether the FormatPercent method displays negative numbers in parentheses. Valid values are vbTrue, vbFalse, and vbUseDefault. |
| [GroupDigits] | Variant Specifies whether the FormatPercent method groups numbers. Valid values are vbTrue, vbFalse, and vbUseDefault. |
| vFormatPercent | Variant Receives the formatted percentage value. |
The following example displays various formats for a percentage value:
Dim MyNumber MyNumber = -12345.6789 Call MsgBox(FormatPercent(MyNumber)) ' Do not group digits Call MsgBox(FormatPercent(MyNumber, , , , vbFalse))