Home >Web Front-end >JS Tutorial >Js 4 effects of retaining decimal points to achieve code sharing_javascript skills

Js 4 effects of retaining decimal points to achieve code sharing_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:52:291069browse
1. Clear the decimal point to zero:
Copy the code The code is as follows:
function returnFloat0 (value) {
value = Math.round(parseFloat(value));
return value;
}

2. Keep one decimal point:
Copy code The code is as follows:
function returnFloat1(value) {
value = Math.round(parseFloat( value) * 10) / 10;
if (value.toString().indexOf(".") < 0) {
value = value.toString() ".0";
}
Return value;
}

3. Keep two decimal points
Copy code The code is as follows:
function returnFloat2(value){
value = Math.round(parseFloat(value) * 100) / 100;
if (value.toString().indexOf( ".") < 0) {
                                                                                                                                       Two decimal points and one decimal point are automatically filled with zeros



Copy code
value = value.toString() ".00";
return value;
}
if(xsd .length>1){
                                                                                                                                                                                              🎜>}
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