当前位置导航:炫浪网>>网络学院>>网页制作>>JavaScript教程

javasript实现第三位小数四舍五入

 var expensevalue = (document.getElementById("edt_0_Expense").value).toString()

                point = expensevalue.indexOf(".");
                //edt_0_Expense.value;
                last = point + 2;
                round = point + 3;
                lastvalue = parseInt(expensevalue.substr(last,1));
                if (parseInt(expensevalue.substr(round,1)) >= 5)
                    lastvalue = parseInt(expensevalue.substr(last,1)) + 1;
                expensevalue = expensevalue.substr(0, last) + lastvalue.toString();

第三位小数四舍五入

或者用库函数

newexpensevalue= parseFloat(Math .round (expensevalue*100))/100;

相关内容
赞助商链接