<html>
<head>
<title>1</title>
</head>
<script>
function ts()
{
document.form1.t1.value=Math.round(((1.09)+(1.98))*100)/100
}
</script><body>
<form name="form1" method="post" action="">
<p>
<input name="t1" type="text" id="t1">
</p>
<p>
<input type="button" name="Submit" value="按鈕" onclick=ts()>
</p>
</form>
</body>
</html>
<head>
<title>1</title>
</head>
<script>
function ts()
{
document.form1.t1.value=Math.round(((1.09)+(1.98))*100)/100
}
</script><body>
<form name="form1" method="post" action="">
<p>
<input name="t1" type="text" id="t1">
</p>
<p>
<input type="button" name="Submit" value="按鈕" onclick=ts()>
</p>
</form>
</body>
</html>
<script>
function ts()
{
document.form1.t1.value=Math.round(((1.09)+(1.98))*100)/100
}
</script>
parseFloat计算有问题?在线等待!1.09+1.98=3.0700000000000003
没任何问题,浮点运算必存在着“精确度”问题,这是每一本计算机语言教程上面必提的
你只需要根据自己需要的精度取一个近似值就行了。并且,二进制在计算小数时就一直没怎么准确过,除非那个小数是“0.5”的倍数
不信你就将十进制的“0.3”手工转换为二进制数看看?
value.toFixed(2)
即可取两位小数