JS rounding problem of special data
2.885 |
7131.0 |
两数相乘:20572.934999999998 |
四舍五入后结果是:20572.93 |
What’s going on?
]
A better solution:
If you need to introduce external Js, you need to refresh to execute
]<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>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn