Định dạng VBScript Chức năng tiền tệ
❮ Toàn bộ tài liệu tham khảo VBScript
Hàm FormatCurrency trả về một biểu thức được định dạng là giá trị tiền tệ bằng cách sử dụ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:
|
Các ví dụ
ví dụ 1
<%
response.write(FormatCurrency(20000))
%>
Đầu ra của đoạn mã trên sẽ là:
$20,000.00
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
Ví dụ 3
Giá trị phân số có hoặc không có số 0 ở đầ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
Ví dụ 4
Giá trị âm bên trong dấu ngoặc đơn hoặc 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)
Ví dụ 5
Nhóm một triệu đô la - hoặc 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
❮ Toàn bộ tài liệu tham khảo VBScript