日期:2014-05-16  浏览次数:20325 次

js金额四舍五入到角,显示到小数点后两位
js金额四舍五入到角,显示到小数点后两位
如13.45678 ==> 13.50

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function cal(obj){
	var num = parseFloat(obj.value);
	var valueInt = Math.round(num*10)/10;
	//toFixed(2)表示精确到小数点后2位
	document.getElementById("t1").value = valueInt.toFixed(2);
}
</script>
</head>
<body>
<input type="text" onchange="cal(this)"></input>
<input id="t1" type="text"></input>
</body>
</html>