87,910
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title>四舍五入</title>
</head>
<body>
<input type='text' id='input_val' style="width:100px; height:20px;"/>
<button id='input_handle'>Click</button>
<div id='value'></div>
</body>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
$('input_handle').onclick = function inputHandle(){
// 作为可设定的值 在此处获取替换掉2
var len =2;
var val = $('input_val').value;
var tempval = val.substring(0,val.indexOf('.') + len + 2);
var value = Math.pow(10,len)
alert(Math.round(tempval * value)/value);
}
</script>
</html>