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

js implements the addition of two values ​​and alerts it accurately to the specified position_javascript skills

WBOY
Release: 2016-05-16 17:21:31
Original
1409 people have browsed it

For example: Number(4.2) Number(9.2)
The sum of these two values ​​​​alerts equal to 13.3999999999999998. Why?

For example: Number(2.2) Number(9.7)
alert equals 11.899999999999998

But like this Number(2.3) Number(9.9)
alert equals 12.2. This value is what I want.

Why do some values ​​have so many decimal places when they add up, while others don’t?

Copy code The code is as follows:


< ;/head>

<script> <br><br>var a=4.2; <br>var b=9.2; <br><br>alert(Number((a b) .toFixed(2))); <br></script>


Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!