VBScript FormatNumber Function | Newbie Tutorial
Newbie Tutorial -- Learning Technology, More Than Just Dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
VBScript FormatNumber Function
The FormatNumber function returns an expression formatted as a number.
Syntax
FormatNumber(Expression[,NumDigAfterDec[, IncLeadingDig[,UseParForNegNum[,GroupDig]]]])| Parameter | Description |
|---|---|
| expression | Required. The expression to be formatted. |
| NumDigAfterDec | Optional. A numeric value indicating the number of digits to display to the right of the decimal point. Default is -1 (uses the computer's locale settings). |
| IncLeadingDig | Optional. Indicates whether leading zeros are displayed for fractional values: * -2 = TristateUseDefault - Uses computer's locale setting * -1 = TristateTrue - True * 0 = TristateFalse - False |
| UseParForNegNum | Optional. Indicates whether negative values are placed in parentheses: * -2 = TristateUseDefault - Uses computer's locale setting * -1 = TristateTrue - True * 0 = TristateFalse - False |
| GroupDig | Optional. Indicates whether numbers are grouped using the grouping symbols specified in the computer's locale setting: * -2 = TristateUseDefault - Uses computer's locale setting * -1 = TristateTrue - True * 0 = TristateFalse - False |
Examples
Example 1
document.write(FormatNumber(20000)) The above example outputs: 20,000.00 Try it Β»Example 2
Set the number of digits after the decimal point: document.write(FormatNumber(20000,2) & "") document.write(FormatNumber(20000,5)) The above example outputs: 20,000.00 20,000.00000 Try it Β»
Example 3
Whether to display leading zeros for fractional values: document.write(FormatNumber(.20,,0) & "") document.write(FormatNumber(.20,,-1)) The above example outputs: .20 0.20 Try it Β»
Example 4
Whether to place negative values in parentheses: document.write(FormatNumber(-50,,,0) & "") document.write(FormatNumber(-50,,,-1)) The above example outputs: -50.00 (50.00) Try it Β»
Example 5
Whether to group numbers: document.write(FormatNumber(1000000,,,,0) & "") document.write(FormatNumber(1000000,,,,-1)) The above example outputs: 1000000.00 1,000,000.00 Try it Β»
YouTip