Using asp how to create formatted currency with commas?

↘锁芯ラ 提交于 2019-12-11 06:35:55

问题


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"

回答1:


use the vbscript function FormatCurrency

complete syntax is: FormatCurrency(Expression[,NumDigAfterDec[, IncLeadingDig[,UseParForNegNum[,GroupDig]]]])

example:

FormatCurrency(20000)

output = $20,000.00

example of setting number of decimals:

FormatCurrency(20000,5)

output = $20,000.00000




回答2:


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):

  1. formatnumber returns an expression formatted as a number.
  2. 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 [,NumDigitsAfterDecimal [,IncludeLeadingDigit
[,UseParensForNegativeNumbers [,GroupDigits]]]]
  1. Expression is the only required argument, that being the number you wish to format.
  2. 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.
  3. 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.
  4. 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.
  5. 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:

  1. -2 is the default and indicates that the default value from the computer's regional setting should be used.
  2. -1 is true.
  3. 0 is false.


来源:https://stackoverflow.com/questions/5783731/using-asp-how-to-create-formatted-currency-with-commas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!