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;
更多精彩
赞助商链接