asp中cint與clng的區(qū)別分析
cint與clng含義:
都可以強(qiáng)制將一個表達(dá)式轉(zhuǎn)換成數(shù)據(jù)類型
cint與clng處理數(shù)據(jù)的范圍:
CInt Integer -32,768 至 32,767,小數(shù)部分四舍五入。
CLng Long -2,147,483,648 至 2,147,483,647,小數(shù)部分四舍五入。
所謂溢出指的是超出處理數(shù)據(jù)的范圍,下面代碼是處理數(shù)據(jù)防止溢出的代碼,大家可以自己看看:
'檢測是否是短整數(shù) sub Is_Int(string) if len(abs(string))>10 then response.write "數(shù)據(jù)溢出":response.end if instr(string,"-")<1 then if cint(left(string,4))>3276 and cint(right(string,1))>7 then response.write "數(shù)據(jù)溢出":response.end else if cint(left(abs(string),4))>3276 and cint(right(string,1))>8 then response.write "數(shù)據(jù)溢出":response.end end if end sub
檢測是否是長整數(shù)
sub Is_Lng(string) if len(abs(string))>10 then response.write "數(shù)據(jù)溢出":response.end if instr(string,"-")<1 then if clng(left(string,9))>214748364 and clng(right(string,1))>7 then response.write "數(shù)據(jù)溢出":response.end else if clng(left(abs(string),9))>21478364 and clng(right(string,1))>8 then response.write "數(shù)據(jù)溢出":response.end end if end sub
具體使用看這個數(shù)字可能最大區(qū)間,一般分頁可以用cint,文章id用clng比較好。
在我以前做asp開發(fā)時,特別是涉及到商務(wù)類的計算時,clng用的比較多,cint主要用于處理短整數(shù)。
有了上面的二個函數(shù),有效防止了溢出,很有用。
相關(guān)文章
ASP javascript Application對象的Contents和StaticObjects做Cache的一些
ASP javascript: Application對象的Contents和StaticObjects做Cache的一些結(jié)論。 ASP封裝Cache對象,一般都是基于Application的,2008-05-05自己寫的文件操作的function和Sub vb.net dll
自己寫的文件操作的function和Sub vb.net dll...2007-08-08asp通過JMAIL實現(xiàn)通用發(fā)送函數(shù)
asp通過JMAIL實現(xiàn)通用發(fā)送函數(shù)...2007-08-08asp取動態(tài)表單中數(shù)據(jù)并寫入xml文件,用xsl顯示
asp取動態(tài)表單中數(shù)據(jù)并寫入xml文件,用xsl顯示...2006-09-09