Home > Web Front-end > JS Tutorial > Solution to the inexplicable error caused by JavaScript using IEEE standards for binary floating point operations_javascript skills

Solution to the inexplicable error caused by JavaScript using IEEE standards for binary floating point operations_javascript skills

WBOY
Release: 2016-05-16 18:06:09
Original
1044 people have browsed it

When JavaScript performs calculations with decimals, a loop of 9 will appear. The following method can help solve it.

The first parameter is the value to be processed, and the second parameter is the number of decimal places to be retained. This is how I use it in my own project~

Copy the code The code is as follows:

function round(v ,e){
var t=1;
for(;e>0;t*=10,e--);
for(;e<0;t/=10,e );
return Math.round(v*t)/t;
}
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