Hàm FormatNumber VBScript


❮ Toàn bộ tài liệu tham khảo VBScript

Hàm FormatNumber trả về một biểu thức được định dạng dưới dạng số.

Cú pháp

FormatNumber(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:
  • -2 = TristateUseDefault - Use the computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
UseParForNegNum Optional. Indicates whether or not to place negative values within parentheses:
  • -2 = TristateUseDefault - Use the computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False
GroupDig Optional. Indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings:
  • -2 = TristateUseDefault - Use the computer's regional settings
  • -1 = TristateTrue - True
  • 0 = TristateFalse - False

Các ví dụ

ví dụ 1

<%

response.write(FormatNumber(20000))

%>

Đầu ra của đoạn mã trên sẽ là:

20,000.00

Ví dụ 2

Đặt số thập phân:

<%

response.write(FormatNumber(20000,2) & "<br />")
response.write(FormatNumber(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(FormatNumber(.20,,0) & "<br />")
response.write(FormatNumber(.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(FormatNumber(-50,,,0) & "<br />")
response.write(FormatNumber(-50,,,-1))

%>

Đầu ra của đoạn mã trên sẽ là:

-50.00
(50.00)

Ví dụ 5

Nhóm số - hoặc không:

<%

response.write(FormatNumber(1000000,,,,0) & "<br />")
response.write(FormatNumber(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