Định dạng VBScriptChức năng tiền tệ
❮ Tham khảo VBScript hoàn chỉnh
Hàm FormatCurrency trả về một biểu thức được định dạng dưới dạng giá trị tiền tệ bằng ký hiệu tiền tệ được xác định trong bảng điều khiển của máy tính.
Cú pháp
FormatCurrency(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
Parameter | Description |
---|---|
expression | Required. The expression to be formatted |
NumDigAfterDec | Optional. Indicates how many places to the right of the decimal are displayed. Default is -1 (the computer's regional settings are used) |
IncLeadingDig | Optional. Indicates whether or not a leading zero is
displayed for fractional values:
|
UseParForNegNum | Optional. Indicates whether or not to place negative
values within parentheses:
|
GroupDig | Optional. Indicates whether or not numbers are grouped
using the group delimiter specified in the computer's regional settings:
|
Ví dụ
ví dụ 1
<%
response.write(FormatCurrency(20000))
%>
Đầu ra của đoạn mã trên sẽ là:
$20,000.00
Hiển thị ví dụ »Ví dụ 2
Cài đặt số thập phân:
<%
response.write(FormatCurrency(20000,2) & "<br />")
response.write(FormatCurrency(20000,5))
%>
Đầu ra của đoạn mã trên sẽ là:
$20,000.00
$20,000.00000
Hiển thị ví dụ »Ví dụ 3
Giá trị phân số có hoặc không có số 0 đứng đầu:
<%
response.write(FormatCurrency(.20,,0) & "<br />")
response.write(FormatCurrency(.20,,-1))
%>
Đầu ra của đoạn mã trên sẽ là:
$.20
$0.20
Hiển thị ví dụ »Ví dụ 4
Giá trị âm có nằm trong ngoặc đơn hay không:
<%
response.write(FormatCurrency(-50,,,0) & "<br />")
response.write(FormatCurrency(-50,,,-1))
%>
Đầu ra của đoạn mã trên sẽ là:
-$50.00
($50.00)
Hiển thị ví dụ »Ví dụ 5
Nhóm một triệu đô la - hay không:
<%
response.write(FormatCurrency(1000000,,,,0) & "<br />")
response.write(FormatCurrency(1000000,,,,-1))
%>
Đầu ra của đoạn mã trên sẽ là:
$1000000.00
$1,000,000.00
Hiển thị ví dụ »❮ Tham khảo VBScript hoàn chỉnh