如何实现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 小弱求问一个javascript问题 responseText中提取td元素的正则表达式再次开贴问题还没搞定 js改变背景图片有事不能显示 JavaScript 值更新问题 在Javascript中如何传递ASP变量? 现在JS是第几版的. 如何使用div标记10秒钟后隐藏? 问个表格效果?????? 一个关闭弹出窗口的问题 下拉列表框有enable属性吗? 如何动态改变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