VBScript FormatNumber Function
❮ การอ้างอิง VBScript ที่สมบูรณ์
ฟังก์ชัน FormatNumber ส่งกลับนิพจน์ที่จัดรูปแบบเป็นตัวเลข
ไวยากรณ์
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:
|
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:
|
ตัวอย่าง
ตัวอย่าง 1
<%
response.write(FormatNumber(20000))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
20,000.00
ตัวอย่าง 2
การตั้งค่าจำนวนทศนิยม:
<%
response.write(FormatNumber(20000,2) & "<br />")
response.write(FormatNumber(20000,5))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
20,000.00
20,000.00000
ตัวอย่างที่ 3
ค่าเศษส่วนที่มีหรือไม่มีศูนย์นำหน้า:
<%
response.write(FormatNumber(.20,,0) & "<br />")
response.write(FormatNumber(.20,,-1))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
.20
0.20
ตัวอย่างที่ 4
ค่าลบภายในวงเล็บหรือไม่:
<%
response.write(FormatNumber(-50,,,0) & "<br />")
response.write(FormatNumber(-50,,,-1))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
-50.00
(50.00)
ตัวอย่างที่ 5
การจัดกลุ่มตัวเลข - หรือไม่:
<%
response.write(FormatNumber(1000000,,,,0) & "<br />")
response.write(FormatNumber(1000000,,,,-1))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
1000000.00
1,000,000.00
❮ การอ้างอิง VBScript ที่สมบูรณ์