Go to: Articles List

Formatting Numbers Part 1 : Integers

The function you need to format numbers is FormatNumber. It is very easy to use and has been outlined and explained below:

FormatNumber(NumToBeFormatted[, NumOfDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers])
- returns a formatted number from the number specified with the appropriate number of digits specified after the decimal
- the first parameter is the only one that is required, although I recommend that you use at least include the second parameter.
- the last two parentheses are tristate values which means you need to specify a -1 for true, 0 for false, or -2 to use the computers regional settings.
- the IncludeLeadingDigit parameter is used to specify whether or not you want a leading zero to be displayed when the number is a fractional value.
- the UseParensForNegativeNumbers parameter is pretty self explanatory, if set to true it will put parentheses around negative numbers.

Example:

var1 = 5443.354
var2 = -877743.2345
Response.Write("var1 formatted = " & FormatNumber(var1, 2, -1, -1) & "<br>")
Response.Write("var2 formatted = " & FormatNumber(var2, 1, -1, -1))

Result:

var1 formatted = 5,443.35
var2 formatted = (877,743.2)