网络编程 
首页 > 网络编程 > 浏览文章

ASP(VBScript)中整除和取余

(编辑:jimmy 日期: 2025/4/24 浏览:3 次 )

整除

ASP(VBScript) 中整除用“\”,比如 m = 5 \ 2,结果为 2。

取余

ASP(VBScript) 中取余用 mod,比如 m = 5 mod 2,结果为 1。

大数注意

m = 4444444444 / 2
n = 4444444444 \ 2

第一句是正确的,第二句运行时会报溢出错误,因为:在整除、取余操作前,数值表达式四舍五入为 Byte、Integer 或 Long 子类型表达式。Long 子类型的范围是 [-2147483648, 2147483647],也就是说,要进入整除或取余的数字必须在这个范围内。

asp中的几个取整函数

asp中的几个取整函数是: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 参数为负数时,Int 函数返回小于或等于 number 的第一个负整数,而 Fix 函数返回大于或等于 number 参数的第一个负整数。例如,Int 将 -8.4 转换为 -9,而 Fix 函数将 -8.4 转换为 -8。

round(Expression[, numdecimalplaces])返回按指定位数进行四舍五入的数值。Expression是必选项。数值表达式 被四舍五入。Numdecimalplaces是可选项。数字表明小数点右边有多少位进行四舍五入。如果省略,则 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>"
%>
上一篇:asp提示无效使用 Null: Replace
下一篇:ASP 提示非法赋值的解决方法
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。