zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

ASP(VBScript)中整除和取余

ASP 取余 VBScript 整除
2023-06-13 09:15:32 时间

整除

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

取余

ASP(VBScript)中取余用mod,比如m=5mod2,结果为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.writeint(2.14)"2
response.writefix(2.14)"2
response.writeint(2.54)"2
response.writeint(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.writeround(3.14)"3
response.writeround(3.55)"4
response.writeround(3.1415,3)"3.142

测试代码:

<%
response.write650\100&"<br>"
response.writeint(650/100)&"<br>"
response.writefix(650/100)&"<br>"
response.writeint(2.54)&"<br>"
response.writeint(2.54)&"<br>"
%>