链接类

VML

按钮类

标题类

表单类

表格类

菜单类

窗口类

对象类

滚动条

键盘类

框架类

例子类

模拟类

日期类

色彩类

鼠标类

数学类

图片类

文字类

下拉框

样式类

游戏类

状态栏

资料类

字幕类

其它类

 ·计算圆周率
 ·100只鸡
 ·阿拉伯数字转换为英文 
 ·装机计算器
 ·三角函数计算
 ·面积计算器
 ·职位
 ·坐标图
 ·科学计算器
您当前位置:好素材首页 -> 网页特效 -> 数学类
查看信息

NUMBER对象的增强函数
好素材网 www.HaoSc.com 02月22日 11:49

[查看演示]  源码如下
----------------------------------------------------------
<script>
//任意位四舍五入
Number.prototype.round=function(n){
//code by windy_sk , seasonx@163.net
if(!/\d/.test(n))return this;
var num = this * Math.pow(10,n);
alert(num);
return Math.round(num)/ Math.pow(10,n);
}
alert((1.237802456).round(3))


//阶乘
Number.prototype.fact=function(){
//code by windy_sk , seasonx@163.net
var num = Math.floor(this);
if(num<0)return NaN;
if(num==0 || num==1)
return 1;
else
return (num*(num-1).fact());
}
alert((4).fact())
</script>

<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div>


此信息共 1 页 [1]