如何把一长串数字分位显示?
程序员文章站
2023-01-25 17:48:31
<%function comma(str)if not(isnumeric(str)) or str =...
<%
function comma(str)
if not(isnumeric(str)) or str = 0 then
result = 0
elseif len(fix(str)) < 4 then
result = str
else
pos = instr(1,str,".")
if pos > 0 then
dec = mid(str,pos)
end if
res = strreverse(fix(str))
loopcount = 1
while loopcount <= len(res)
tempresult = tempresult + mid(res,loopcount,3)
loopcount = loopcount + 3
if loopcount <= len(res) then
tempresult = tempresult + ","
end if
wend
result = strreverse(tempresult) + dec
end if
comma = result
end function
%>
<html>
<body>
<%
alongnumber = "12345678"
%>
原来的数字: <%=alongnumber%><br>
用逗号格式化后: <%=comma(alongnumber)%>
</body></html>