为什么会出现下面现象,有没有办法解决
<html>
<head>
</head>
<body>
a= <INPUT id= "a " type= "text " onfocus= "a() " onblur= "a() ">
b= <INPUT id= "b " type= "text " onfocus= "a() " onblur= "a() ">
结果: <input id= "c " type= "text ">
</body>
</html>
<script language=javascript>
function a()
{
var a=document.getElementById( "a ").value;
var b=document.getElementById( "b ").value;
document.getElementById( "c ").value=parseFloat(a)*parseFloat(b);
}
</script>
当a=50.4 b=21 时,结果为1058.3999999999998
当a=50.1 b=21 时,结果为1052.1000000000001
------解决方案--------------------JavaScript 数字的精度不高,你可以使用 toFixed() 的方法纠正