VBScript FormatNumber Function

Definition and Usage

The FormatNumber function can return the expression formatted as a number.

Syntax

FormatNumber(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
Parameters Description
expression Required. The expression to be formatted.
NumDigAfterDec Indicates the number of digits to display to the right of the decimal point. The default value is -1 (using the computer's regional settings).
IncLeadingDig Optional. Indicates whether to display leading zeros (leading zero) for decimal values:
  • -2 = TristateUseDefault - Use the settings in the computer's regional settings.
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
UseParForNegNum Optional. Indicates whether to place negative values in parentheses.
  • -2 = TristateUseDefault - Use the settings in the computer's regional settings.
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
GroupDig Optional. Indicates whether to use the number grouping symbol specified in the computer's regional settings to group numbers.
  • -2 = TristateUseDefault - Use the settings in the computer's regional settings.
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False

Instance

Example 1

document.write(FormatNumber(20000))

Output:

20,000.00

Example 2

document.write(FormatNumber(20000.578,2))

Output:

20,000.58

Example 3

document.write(FormatNumber(20000.578,2,,,0))

Output:

20000.58