VBScript FormatCurrency 函數

FormatCurrency 函數返回作為貨幣值被格式化的運算式,使用電腦系統控制面板中定義的貨幣符號。
語法
FormatCurrency(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
參數 | 描述 |
---|---|
expression | 必需。需被格式化的運算式。 |
NumDigAfterDec | 可選。指示小數點右側顯示位數的數值。默認值為 -1(使用的是電腦的區域設置)。 |
IncLeadingDig | 可選。指示是否顯示小數值的前導零:
|
UseParForNegNum | 可選。指示是否將負值置於括弧中:
|
GroupDig | 可選。指示是否使用電腦區域設置中指定的數字分組符號將數字分組:
|
實例
實例 1
<script type="text/vbscript">
document.write(FormatCurrency(20000))
</script>
document.write(FormatCurrency(20000))
</script>
以上實例輸出結果:
$20,000.00
實例 2
設置小數點後的位數:
<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>
以上實例輸出結果:
$20,000.00
$20,000.00000
$20,000.00000
實例 3
是否顯示小數值的前導零:
<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>
以上實例輸出結果:
$.20
$0.20
$0.20
實例 4
是否將負值置於括弧中:
<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>
以上實例輸出結果:
-$50.00
($50.00)
($50.00)
實例 5
是否將一百萬美元分組:
<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>
以上實例輸出結果:
$1000000.00
$1,000,000.00
$1,000,000.00
