电脑技术学习

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

dn001

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;