Home > Web Front-end > JS Tutorial > body text

js rounding problem of special data_basic knowledge

WBOY
Release: 2016-05-16 19:18:20
Original
930 people have browsed it
JS rounding problem of special data

2.885 7131.0 两数相乘:20572.934999999998 四舍五入后结果是:20572.93
What’s going on?

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

A better solution:

[Ctrl A select all Note:
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>
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template