当前位置:首页 > ASP教程 > ASP基础

asp cint clng的范围与防止cint和clng的溢出解决方法大全

首先我们需要了解的是

cint范围 -32,768 到 32,767。
clng范围 -2,147,483,648 到 2,147,483,647。

cint与clng含义:

都可以强制将一个表达式转换成数据类型

cint与clng处理数据的范围:

CInt Integer -32,768 至 32,767,小数部分四舍五入。
CLng Long -2,147,483,648 至 2,147,483,647,小数部分四舍五入。

所谓溢出指的是超出处理数据的范围,下面代码是处理数据防止溢出的代码,大家可以自己看看:

'检测是否是短整数
代码如下:

<BR />sub Is_Int(string) <BR />if len(abs(string))>10 then response.write "数据溢出":response.end <BR />if instr(string,"-")<1 then <BR />if cint(left(string,4))>3276 and cint(right(string,1))>7 then response.write "数据溢出":response.end <BR />else <BR />if cint(left(abs(string),4))>3276 and cint(right(string,1))>8 then response.write "数据溢出":response.end <BR />end if <BR />end sub <BR /> <br /><br />'检测是否是长整数 <BR /><span><U></U></span> 代码如下:
<BR />sub Is_Lng(string) <BR />if len(abs(string))>10 then response.write "数据溢出":response.end <BR />if instr(string,"-")<1 then <BR />if clng(left(string,9))>214748364 and clng(right(string,1))>7 then response.write "数据溢出":response.end <BR />else <BR />if clng(left(abs(string),9))>21478364 and clng(right(string,1))>8 then response.write "数据溢出":response.end <BR />end if <BR />end sub <BR /><br /><br /><STRONG>以下是一些检验函数,需要的朋友可以参考下:<BR /></STRONG><BR />第一种:<BR /><STRONG>一、检测它是不是整数</STRONG> <BR /><span><U></U></span> 代码如下:<BR />function Is_Int(a_str)   <BR />   if not isnumeric(a_str) or len(str) > 5 then   <BR />      Is_Int = false    <BR />      exit function    <BR />   elseif len(str) < 5 then   <BR />      Is_Int = true    <BR />      exit function    <BR />   end if      <BR />   if cint(left(a_str , 4)) > 3276 then   <BR />      Is_Int = false   <BR />      exit function   <BR />   elseif cint(left(a_str , 4)) = 3276 and cint(right(a_str , 1)) > 7 then   <BR />      Is_Int = false   <BR />      exit function   <BR />   else   <BR />      Is_Int = true   <BR />      exit function   <BR />   end if      <BR />end function  <BR /><br /><br />  <br /><br /><STRONG>二、检测它是不是长整数</STRONG> <br /><br /><span><U></U></span> 代码如下:<BR />function Is_Lng(a_str)   <BR />   if not isnumeric(a_str) or len(str) > 10 then   <BR />      Is_Lng = false   <BR />      exit function    <BR />   elseif len(str) < 10 then   <BR />      Is_Lng = true    <BR />      exit function    <BR />   end if      <BR />   if clng(left(a_str , 9)) > 214748367 then   <BR />      Is_Lng = false   <BR />      exit function   <BR />   elseif clng(left(a_str , 9)) = 214748367 and clng(right(a_str , 1)) > 7 then   <BR />      Is_Lng = false   <BR />      exit function   <BR />   else   <BR />      Is_Lng = true   <BR />      exit function   <BR />   end if      <BR />end function  <BR /><BR />如果我们只需要是数子,其它的东西,都可以替换为空,下面这个是硕编程站长写的一个正则,替换非数字的正则<BR /><span><U></U></span> 代码如下:<BR />function replacestr(str) <BR />dim re <BR />set re=new regexp <BR />re.ignorecase=true <BR />re.global=true <BR />re.pattern="D" <BR />str=re.replace(str,"") <BR />replacestr=str <BR />set re=nothing <BR />end function<BR /><BR />下面是上面的调用方法<BR /><span><U></U></span> 代码如下:<BR />id=replacestr(id) <BR />if len(id)>5 then id=left(id,5) <BR />if id<>"" then id=clng(id) <BR />if err.number<>0 Or id="0" then response.redirect "//www.51frw.cn" <BR />dim rs <BR />set rs=conn.execute("select id from news where id="&id&"")<BR />
            
            


           
                
                                                

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐