Using asp. Trying to format a decimal number to add commas. Are there simple to use functions or techniques in asp to go from a decimal value to currency format with commas?
Examples:
DecimalValue = 3439.01 CurrencyValue = " 3,439.01" DecimalValue = 3843838.38 CurrencyValue = "3,843,838.00"
use the vbscript function FormatCurrency
complete syntax is: FormatCurrency(Expression[,NumDigAfterDec[, IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
example:
output = $20,000.00
example of setting number of decimals:
output = $20,000.00000
To expand on Carlton Jenke's answer, there are 2 functions you can use for this (you mentioned formatting as a currency in the question title but don't include currency symbols in the body of the question):
formatnumber
returns an expression formatted as a number.formatcurrency
returns an expression formatted as a currency value using the currency symbol defined in the system control panel.Both functions take the same arguments, those being:
Expression
is the only required argument, that being the number you wish to format.NumDigitsAfterDecimal
is a numeric value specifying how many decimal places you want to round to. The default value is -1, which indicates that the computer's regional settings should be used.IncludeLeadingDigit
is a tristate constant (see below) which specifies whether or not you want to include a leading zero for values between -1 and 1.UseParensForNegativeNumbers
is another tristate constant which specifies whether or not you want negative values to be enclosed in parentheses, rather than using a minus symbol.GroupDigits
, which is the argument you're after, is also a tristate constant and is used to specify whether or not you want to group numbers using the system's group delimiter.The tristate constants takes one of the following for the value:
-2
is the default and indicates that the default value from the computer's regional setting should be used.-1
is true.0
is false.