精华的asp代码39

判断偶数和奇数:
    要真说出来哪一个函数能够做得到,还真难。但我们可用下面的代码来进行识别,返回“假”即偶数,返回“真”则奇数:
function Is_odd(num) as boolean
n=num mod 2
if n=1 then
Is_odd=true
else
Is_odd=false
end if
end function

 

把一长串数字分位显示:
<%
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>

版权声明:
作者:Kiyo
链接:https://www.wkiyo.cn/html/2008-01/i123.html
来源:Kiyo's space
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>