VBScript FormatCurrencyFunction
Complete VBScript Reference
The FormatCurrency function returns an expression formatted as a currency value, using the currency symbol defined in the computer system's Control Panel.
Syntax
FormatCurrency(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
| Parameters | Description |
|---|---|
| expression | Required. The expression to be formatted. |
| NumDigAfterDec | Optional. A numeric value indicating the number of digits displayed to the right of the decimal point. The default value is -1 (uses the computer's regional settings). |
| IncLeadingDig | Optional. Indicates whether to display leading zeros for fractional values:
|
| UseParForNegNum | Optional. Indicates whether negative values are placed within parentheses:
|
| GroupDig | Optional. Indicates whether to group digits using the digit grouping symbol specified in the computer's regional settings:
|
Examples
Example 1
<script type="text/vbscript">
document.write(FormatCurrency(20000))
</script>
document.write(FormatCurrency(20000))
</script>
The output of the above example:
$20,000.00
Try it yourself »
Example 2
Set the number of digits after the decimal point:
<script type="text/vbscript">
document.write(FormatCurrency(20000,2) & "<br />")
document.write(FormatCurrency(20000,5))
</script>
document.write(FormatCurrency(20000,2) & "<br />")
document.write(FormatCurrency(20000,5))
</script>
The output of the above example:
$20,000.00
$20,000.00000
$20,000.00000
Try it yourself »
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>
document.write(FormatCurrency(.20,,0) & "<br />")
document.write(FormatCurrency(.20,,-1))
</script>
The output of the above example:
$.20
$0.20
$0.20
Try it yourself »
Example 4
Whether to place negative values within parentheses:
<script type="text/vbscript">
document.write(FormatCurrency(-50,,,0) & "<br />")
document.write(FormatCurrency(-50,,,-1))
</script>
document.write(FormatCurrency(-50,,,0) & "<br />")
document.write(FormatCurrency(-50,,,-1))
</script>
The output of the above example:
-$50.00
($50.00)
($50.00)
Try it yourself »
Example 5
Whether to group one million dollars:
<script type="text/vbscript">
document.write(FormatCurrency(1000000,,,,0) & "<br />")
document.write(FormatCurrency(1000000,,,,-1))
</script>
document.write(FormatCurrency(1000000,,,,0) & "<br />")
document.write(FormatCurrency(1000000,,,,-1))
</script>
The output of the above example:
$1000000.00
$1,000,000.00
$1,000,000.00
Try it yourself »
Complete VBScript Reference Other extensions