首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 代码乐园 >
    7i24 .Com  
  把长的数字用逗号隔开显示

7i24.Com不停为您服务
把长的数字用逗号隔开显示

Code Title: Proper Number
Description: If you have a long number to display, then why not make it split the number up correctly with
a comma?

For example, the number 12345678 looks odd, right? Ok, let's apply the Comma() function to that number and
display it like this automatically: 12,345,678 -much cleaner!

By the way, this script supports numbers as long as 15 characters (numbers), so if you have a longer
number than that, we may need to work together to advance this script a bit, but this snippet will work
just fine for your average numbers. Thanx to Dave Cantrell for this advice!
Copy and paste this snippet as-is into your editor:

000000000000000000000000000000000000000000000000000000000000000
<%
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"
%>
An un-formatted number: <%=aLongNumber%>

The Comma formatted number: <%=Comma(aLongNumber)%>
</body>
</html>




  2002年1月9日  阅读 767 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 遍历目录以及目录下文件的函数
下一篇: 用正则表达式突出显示字符串中查询到的单词的函数
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利