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

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

WBOY
Release: 2016-05-16 16:52:29
Original
1027 people have browsed it
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){
                                                                                                                                                                                              🎜>}
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!