Fungsi VBScript FormatCurrency
Fungsi FormatCurrency mengembalikan nilai diformat sebagai ekspresi moneter, menggunakan panel kontrol sistem komputer untuk menentukan simbol mata uang.
tatabahasa
FormatCurrency(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
参数 | 描述 |
---|---|
expression | 必需。需被格式化的表达式。 |
NumDigAfterDec | 可选。指示小数点右侧显示位数的数值。默认值为 -1(使用的是计算机的区域设置)。 |
IncLeadingDig | 可选。指示是否显示小数值的前导零:
|
UseParForNegNum | 可选。指示是否将负值置于括号中:
|
GroupDig | 可选。指示是否使用计算机区域设置中指定的数字分组符号将数字分组:
|
contoh
contoh 1
<script type="text/vbscript">
document.write(FormatCurrency(20000))
</script>
document.write(FormatCurrency(20000))
</script>
Contoh output di atas:
$20,000.00
Coba »
contoh 2
Menetapkan jumlah tempat desimal:
<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>
Contoh output di atas:
$20,000.00
$20,000.00000
$20,000.00000
Coba »
contoh 3
Apakah akan menampilkan nol terkemuka untuk nilai pecahan:
<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>
Contoh output di atas:
$.20
$0.20
$0.20
Coba »
contoh 4
Apakah nilai-nilai negatif dalam kurung:
<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>
Contoh output di atas:
-$50.00
($50.00)
($50.00)
Coba »
contoh 5
Akankah juta dolar pengelompokan:
<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>
Contoh output di atas:
$1000000.00
$1,000,000.00
$1,000,000.00
Coba »
Lengkap VBScript Referensi