<span class="bold">特殊数据的js四舍五入问题</span><br><br> <div style="FONT-SIZE: 12px"> <table class="t_table" width="75%" align="center"> <tbody> <tr> <td>2.885</td> <td>7131.0</td> <td>两数相乘:20572.934999999998</td> <td>四舍五入后结果是:20572.93</td> </tr> </tbody> </table>怎么回事啊?<br><div class="htmlarea"> <textarea id="runcode23780"> <script> var s = 2, n = 20572.934999999998; var l = n.toString().length - (n.toString().indexOf('.') + 1); for (var i = l; i >= s; i --) { n = new Number(n.toFixed(i)); } alert(n); </script> </textarea><br><input onclick="runEx('runcode23780')" type="button" value="运行代码"> <input onclick="doCopy('runcode23780')" type="button" value="复制代码"> <input onclick="doSave(runcode23780)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>比较好的解决方法:<br><div class="htmlarea"> <textarea id="runcode15494"> <script language="JavaScript"> t=100000; alert((2.885*t) * (7131.0*t) / (t*t)); </script> </textarea><br><input onclick="runEx('runcode15494')" type="button" value="运行代码"> <input onclick="doCopy('runcode15494')" type="button" value="复制代码"> <input onclick="doSave(runcode15494)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> </div>