var ratioNow222 = (money-fastPriceOrRatio)/money; var ratioNow = Number(ratioNow222.toFixed(2)); if( ratioNow > commissionMax ) { textFastPriceOrRatio.html("<font color='red'>价格设置不能超出佣金比率上限"+commissionMax+"!</font>"); checkFastPriceOrRatio = false; return; } if( ratioNow < commissionMin ) { textFastPriceOrRatio.html("<font color='red'>价格设置不能低于佣金比率下限"+commissionMin+"!</font>"); checkFastPriceOrRatio = false; return; }
?
###主要使用了Number(ratioNow222.toFixed(2));? 保留2位小数,转换成Number
?
###其他方法:
<script> /*四舍五入*/ var num=22.127456; alert( Math.round(num*100)/100); /*四舍五入*/ var num=22.127456; alert( num.toFixed(2)); /*非四舍五入,直接取两位*/ var s = 22.127456 + ""; var str = s.substring(0,s.indexOf(".") + 3); alert(str); /*非四舍五入,直接取两位*/ var a = "23.456322"; var aNew; var re = /([0-9]+\.[0-9]{2})[0-9]*/; aNew = a.replace(re,"$1"); alert(aNew); </script>
?
?
?
?