IT码农库

您当前所在位置:首页 > 网络编程 > 编程10000问

编程10000问

如何把一长串数字分位显示?

互联网 2006-11-16编程10000问6050
<%Function Comma(str)If Not(IsNumeric(str)) Or str = 0 Then  Result = 0ElseIf Len(Fix(str)) < 4 Then  Result = strElse  Pos = Instr(1,str,".")  If Pos > 0 Then  Dec = Mid(str,Pos)  End if  Res = StrReverse(Fix(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>

大图广告(830*140)