<script>
var num = 3.7*3
//方法1:
alert(num+"保留小数点后两位是:"+(num).toFixed(1)) //IE5.5+自带//方法2:
function Number.prototype.Fixed(n){
with(Math){var tmp=pow(10,n);return round(this*tmp)/tmp;}
}
alert(num+"保留小数点后两位是:"+num.Fixed(1));
</script>
var num = 3.7*3
//方法1:
alert(num+"保留小数点后两位是:"+(num).toFixed(1)) //IE5.5+自带//方法2:
function Number.prototype.Fixed(n){
with(Math){var tmp=pow(10,n);return round(this*tmp)/tmp;}
}
alert(num+"保留小数点后两位是:"+num.Fixed(1));
</script>
解决方案 »
- IE6,IE7下div被textarea挡住
- 为何不同结果
- 用nicEdit后怎么不能自动添加textarea的信息
- 求一段jquery loading代码?
- JavaScript有没有变量名的变量? 一个奇怪的问题
- 在firefox中为什么document.write(xml.transformNode(xsl));会出错呢,请大侠帮忙!!!
- GOOGLE搜索框鼠标聚焦 100元
- HTML select的上移下移该如何写算法?
- 各位--Netscape下非脚本(windows.open)打开的窗口如何关闭?
- 怎么控制TEXT里的最长字符数?
- 高手救急?如何才能让IE里表示的画面和TABLE的定义值吻合呢
- 关于在窗体中的doLoad()方法内,主动设置IE工具栏状态栏的解决方案
Number.prototype.fix = function(num)
{with(Math)return round(this.valueOf()*pow(10,num))/pow(10,num);
}
alert((3.7*3).fix(1));
</script>
if(!Number.prototype.toFixed) {
Number.prototype.toFixed = function(n) {
with(Math) return round(Number(this)*pow(10,n))/pow(10,n)
}
}
alert((3.7*3)+"\n"+(3.7*3).toFixed(1));
</SCRIPT>