- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > ASP >
- ASP(VBScript)中整除和取余
整除
ASP(VBScript) 中整除用“\”,比如 m = 5 \ 2,結果為 2。
取余
ASP(VBScript) 中取余用 mod,比如 m = 5 mod 2,結果為 1。
大數注意
m = 4444444444 / 2
n = 4444444444 \ 2
第一句是正確的,第二句運行時(shí)會(huì )報溢出錯誤,因為:在整除、取余操作前,數值表達式四舍五入為 Byte、Integer 或 Long 子類(lèi)型表達式。Long 子類(lèi)型的范圍是 [-2147483648, 2147483647],也就是說(shuō),要進(jìn)入整除或取余的數字必須在這個(gè)范圍內。
asp中的幾個(gè)取整函數
asp中的幾個(gè)取整函數是:fix(),int(),round();
Int(number)、Fix(number)函數返回數字的整數部分。number 參數可以是任意有效的數值表達式。如果 number 參數包含 Null,則返回 Null。
例:
代碼如下:
response.write int(2.14) '2
response.write fix(2.14) '2
response.write int(2.54) '2
response.write int(2.54) '2
Int 和 Fix 函數都刪除 number 參數的小數部分并返回以整數表示的結果。Int 和 Fix 函數的區別在于如果 number 參數為負數時(shí),Int 函數返回小于或等于 number 的第一個(gè)負整數,而 Fix 函數返回大于或等于 number 參數的第一個(gè)負整數。例如,Int 將 -8.4 轉換為 -9,而 Fix 函數將 -8.4 轉換為 -8。
round(Expression[, numdecimalplaces])返回按指定位數進(jìn)行四舍五入的數值。Expression是必選項。數值表達式 被四舍五入。Numdecimalplaces是可選項。數字表明小數點(diǎn)右邊有多少位進(jìn)行四舍五入。如果省略,則 Round 函數返回整數。
例:
代碼如下:
response.write round(3.14) '3
response.write round(3.55) '4
response.write round(3.1415,3) ' 3.142
測試代碼:
<% response.write 650\100&"<br>" response.write int(650/100)&"<br>" response.write fix(650/100)&"<br>" response.write int(2.54)&"<br>" response.write int(2.54)&"<br>" %>
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站