1。丢弃小数部分,保留整数部分parseInt(5/2)2。向上取整,有小数就整数部分加1Math。ceil(5/2)3,四舍五入。Math。round(5/2)4,向下取整Math。
floor(5/2)Math 对象的方法FF: Firefox, N: Netscape, IE: Internet Explorer方法 描述 FF N IEabs(x) 返回数的绝对值 1 2 3acos(x) 返回数的反余弦值 1 2 3asin(x) 返回数的反正弦值 1 2 3atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值 1 2 3atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间) 1 2 3ceil(x) 对一个数进行上舍入。
1 2 3cos(x) 返回数的余弦 1 2 3exp(x) 返回 e 的指数。 1 2 3floor(x) 对一个数进行下舍入。 1 2 3log(x) 返回数的自然对数(底为e) 1 2 3max(x,y) 返回 x 和 y 中的最高值 1 2 3min(x,y) 返回 x 和 y 中的最低值 1 2 3pow(x,y) 返回 x 的 y 次幂 1 2 3random() 返回 0 ~ 1 之间的随机数 1 2 3round(x) 把一个数四舍五入为最接近的整数 1 2 3sin(x) 返回数的正弦 1 2 3sqrt(x) 返回数的平方根 1 2 3tan(x) 返回一个角的正切 1 2 3toSource() 代表对象的源代码 1 4 -valueOf() 返回一个 Math 对象的原始值代码案例:<script type="text/javascript">//取整function getResult(num){return parseInt(num);}//四舍五入到num后面的n位function getResult(num,n){return Math。
round(num*Math。pow(10,n))/Math。pow(10,n);}//截取n位function getresult(num,n){return num。
toString()。replace(new RegExp("^(\\-?\\d*\\。\\d{0,"+n+"})(\\d*)$"),"$1")+0;}</script>其他:var mLength = textMn。
length; var mFirst = parseInt(mLength/60); //取整 //alert(mLength); var mLast = mLength; //取余 if(mLast>0){ $("mood_content")。
height((mFirst+1)*20); }。 。