[查看演示] 源码如下 ---------------------------------------------------------- <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> |