Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  Asp  >  正文 asp clng与cint的区别及防溢出函数(自定义)

asp clng与cint的区别及防溢出函数(自定义)

发布时间:2014-07-20   编辑:www.jquerycn.cn
为大家介绍asp中的二个函数,clng与cint函数,都可以用于表达式数据类型的强制转换,有需要的朋友,可以参考下。

首先,cint与clng含义:
都可以强制将一个表达式转换成数据类型

cint与clng处理数据的范围:
CInt    Integer       -32,768 至 32,767,小数部分四舍五入。
CLng    Long         -2,147,483,648 至 2,147,483,647,小数部分四舍五入。

这里说的溢出是指超出处理数据的范围。

为大家提供二个防止数据溢出的自定义函数,供大家学习参考。

复制代码 代码示例:

'检测是否是短整数
sub Is_Lng(string)
if len(abs(string))>10 then response.write "数据溢出":response.end
if instr(string,"-")<1 then
       if cint(left(string,4))>3276 and cint(right(string,1))>7 then response.write "数据溢出":response.end
    else
      if cint(left(abs(string),4))>3276 and cint(right(string,1))>8 then response.write "数据溢出":response.end
   end if
end sub

'检测是否是长整数
sub Is_Lng(string)
if len(abs(string))>10 then response.write "数据溢出":response.end
if instr(string,"-")<1 then
       if clng(left(string,9))>214748364 and clng(right(string,1))>7 then response.write "数据溢出":response.end
    else
      if clng(left(abs(string),9))>21478364 and clng(right(string,1))>8 then response.write "数据溢出":response.end
   end if
end sub

在我以前做asp开发时,特别是涉及到商务类的计算时,clng用的比较多,cint主要用于处理短整数。
有了上面的二个函数,有效防止了溢出,很有用。

您可能感兴趣的文章:
asp clng与cint的区别及防溢出函数(自定义)
ASP中字符与数字操作函数总结
C语言的数据类型整型溢出
VBScript的数据类型
ASP 全新接触(1)
php特殊字符转义详解
MicrosoftVBscript运行时错误
python和c语言的区别是什么
ASP VBScript 函数速查表
jQuery自定义函数应用以及解析

[关闭]