如何实现parseFloat保留小数点后2位 t=Math.round(t*100)/100;alert(t); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 value=Math.round(value*100)/100; <script language=JavaScript>function tofloat(f,dec) { if(dec<0) return "Error:dec<0!"; result=parseInt(f)+(dec==0?"":"."); f-=parseInt(f); if(f==0) for(i=0;i<dec;i++) result+='0'; else { for(i=0;i<dec;i++) f*=10; result+=parseInt(Math.round(f)); } return result; } alert(tofloat(11.20000000000000000001,2))</script> function roundFun(numberRound,roundDigit) { with(Math){ return round(numberRound*pow(10,roundDigit))/pow(10,roundDigit); }}alert(roundFun(1112.01111,-2));//精度为:100alert(roundFun(1112.01111,2));//精度为:0.01 昨天前端面试经历 setInterval为什么不能获取数组对象中的属性值 用js怎样实现鼠标控制图片旋转 帮忙看看我的代码 FCKeditor 的几个问题 请问下 jquery中find("> *")代表啥意思呢? 怎样在html页面上直接进行添加、删除、修该操作!(特别着急!) 这样为什么不行?(遍历对象属性) 请问,谁有根据生日来计算年龄的JAVASCRIPT的吗?谢谢,很急 关于浮动图片如何点击后弹出一个POP窗口? 如何动态改变iframe的高和宽 我想找一个日历/月历
function tofloat(f,dec) {
if(dec<0) return "Error:dec<0!";
result=parseInt(f)+(dec==0?"":".");
f-=parseInt(f);
if(f==0)
for(i=0;i<dec;i++) result+='0';
else {
for(i=0;i<dec;i++) f*=10;
result+=parseInt(Math.round(f));
}
return result;
}
alert(tofloat(11.20000000000000000001,2))
</script>
{
with(Math){
return round(numberRound*pow(10,roundDigit))/pow(10,roundDigit);
}
}alert(roundFun(1112.01111,-2));//精度为:100
alert(roundFun(1112.01111,2));//精度为:0.01