Latest web development tutorials

VBScript FormatCurrency function

VBScript Reference Complete VBScript Reference

FormatCurrency function returns the value formatted as a monetary expression, using a computer system control panel to define the currency symbol.

grammar

FormatCurrency(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])

参数 描述
expression 必需。需被格式化的表达式。
NumDigAfterDec 可选。指示小数点右侧显示位数的数值。默认值为 -1(使用的是计算机的区域设置)。
IncLeadingDig 可选。指示是否显示小数值的前导零:
  • -2 = TristateUseDefault - 使用计算机的区域设置
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
UseParForNegNum 可选。指示是否将负值置于括号中:
  • -2 = TristateUseDefault - 使用计算机的区域设置
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
GroupDig 可选。指示是否使用计算机区域设置中指定的数字分组符号将数字分组:
  • -2 = TristateUseDefault - 使用计算机的区域设置
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False

Examples

Example 1

<script type="text/vbscript">

document.write(FormatCurrency(20000))

</script>

Examples of the above output:

$20,000.00

try it"

Example 2

Set the number of decimal places:

<script type="text/vbscript">

document.write(FormatCurrency(20000,2) & "<br />")
document.write(FormatCurrency(20000,5))

</script>

Examples of the above output:

$20,000.00
$20,000.00000

try it"

Example 3

Whether to display leading zeros for fractional values:

<script type="text/vbscript">

document.write(FormatCurrency(.20,,0) & "<br />")
document.write(FormatCurrency(.20,,-1))

</script>

Examples of the above output:

$.20
$0.20

try it"

Example 4

Whether negative values ​​within parentheses:

<script type="text/vbscript">

document.write(FormatCurrency(-50,,,0) & "<br />")
document.write(FormatCurrency(-50,,,-1))

</script>

Examples of the above output:

-$50.00
($50.00)

try it"

Example 5

Will a million dollars grouping:

<script type="text/vbscript">

document.write(FormatCurrency(1000000,,,,0) & "<br />")
document.write(FormatCurrency(1000000,,,,-1))

</script>

Examples of the above output:

$1000000.00
$1,000,000.00

try it"

VBScript Reference Complete VBScript Reference