关于javascript 小数相减!

来源:百度知道 编辑:UC知道 时间:2024/05/09 18:51:36
在IE地址栏输入,javascript:alert(305.77-1.11);
会显示304.6599999999996而不是304.66这是为什么???有什么办法解决这个问题!

<script language="javascript">
/*
* ForDight(Dight,How):数值格式化函数,Dight要
* 格式化的 数字,How要保留的小数位数。
*/
function ForDight(Dight,How)
{
Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
}
alert(ForDight(12345.67890,2));
</script>