The following table shows the possible number formatting functions in VBScript. Number Formatting Functions help the developers to handle numbers in an efficient way and express the numbers in the desired format.
Function |
Description |
FormatNumber |
A Function, which would return an expression formatted as a number |
FormatPercent |
A Function, which would return an expression formatted as a percentage |
FormatNumber() Function
The FormatNumber function in VBScript returns an expression formatted as a number.
FormatNumber(Expression[,NumDigAfterDec[,IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
Parameter |
Description |
Expression |
Required. The expression to be formatted |
NumDigAfterDec |
Optional. Indicates how many places to the right of the decimal are displayed. Default is -1 (the computer's regional settings are used) |
IncLeadingDig |
Optional. Indicates whether or not a leading zero is displayed for fractional values:
- -2 = TristateUseDefault - Use the computer's regional settings
- -1 = TristateTrue - True
- 0 = TristateFalse - False
|
UseParForNegNum |
Optional. Indicates whether or not to place negative values within parentheses:
- -2 = TristateUseDefault - Use the computer's regional settings
- -1 = TristateTrue - True
- 0 = TristateFalse - False
|
GroupDig |
Optional. Indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings:
- -2 = TristateUseDefault - Use the computer's regional settings
- -1 = TristateTrue - True
- 0 = TristateFalse - False
|
Examples
FormatNumber(10000) '10,000.00
FormatNumber(10000, 0) '10,000
FormatNumber(10000, 2) '10,000.00
FormatNumber(.15,,0) '.15
FormatNumber(.15,,-1) '0.15
FormatNumber(-10,,,0) '-10
FormatNumber(-50,,,-1) '(10)
FormatNumber(10000,,,,0) '10000.00
FormatNumber(10000,,,,-1) '10,000.00