VBScript FormatPercentFunction


VBScript 参考手册Complete VBScript Reference

The FormatPercent function returns an expression formatted as a percentage (multiplied by 100) with a trailing % symbol.

Syntax

FormatPercent(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])

Parameters Description
expression Required. Expression to be formatted.
NumDigAfterDec Optional. A value indicating how many digits are displayed to the right of the decimal point. Default value is -1 (uses the computer's regional settings).
IncLeadingDig Optional. Indicates whether a leading zero is displayed for fractional values:
  • -2 = TristateUseDefault - use computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
UseParForNegNum Optional. Indicates whether negative values are placed in parentheses:
  • -2 = TristateUseDefault - use computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
GroupDig Optional. Indicates whether numbers are grouped using the digit grouping symbol specified in the computer's regional settings:
  • -2 = TristateUseDefault - use computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False

Example 1

'How many percent is 6 of 345?
document.write(FormatPercent(6/345))

Output:

1.74%

Example 2

'How many percent is 6 of 345?
document.write(FormatPercent(6/345,1))

Output:

1.7%


VBScript 参考手册Complete VBScript Reference Other Extensions