Home > Web Front-end > JS Tutorial > JS retains two decimal places and multiple decimal places sample code_javascript skills

JS retains two decimal places and multiple decimal places sample code_javascript skills

WBOY
Release: 2016-05-16 17:05:08
Original
1159 people have browsed it

Copy code The code is as follows:



There are also the following methods:
Copy code The code is as follows:

var test=88888.234;
alert(test.toFixed( 2));

// Float data is rounded to 2 decimal places;
function to2bits(flt) {
if(parseFloat(flt) == flt)
return Math.round(flt * 100) / 100;
// to 4 decimal places, return Math.round(flt * 10000) / 10000;
else
return 0;
}

Related labels:
js
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