Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:05:081043browse

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;
}

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