javascript有一个怪现象,就是减法也会导致小数位数问题,是一个麻烦的问题,比如。
<html>
<script>
var a=10,b=20.1;
alert( a - b);
</script>
<body>
</body>
</html>
得到的结果是
-10.100000000000001
想要得到正确的结果,不的不
<html>
<script>
var a=10,b=20.1;
alert( (a - b).toFixed(1) );
</script>
<body>
</body>
</html>
真是悲催哦!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!