WEB开发网
开发学院网页设计JavaScript javasript实现第三位小数四舍五入 阅读

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

 2009-01-19 20:03:28 来源:WEB开发网   
核心提示: var expensevalue = (document.getElementById("edt_0_Expense").value).toString() point = expensevalue.indexOf("."); //edt_0_Expense.value;

 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;

Tags:javasript 实现 第三

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接