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

Introduction to five methods of JavaScript rounding

不言
Release: 2019-03-26 10:19:07
forward
6758 people have browsed it

This article brings you an introduction to the five methods of rounding in JavaScript. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. Math.floor() rounds down

Math.floor(3.141592654) 
// 3
Copy after login

2. Math.ceil() rounds up

Math.floor(3.141592654) 
// 4
Copy after login

3. Math.round() rounds

Math.round(3.141592654) 
// 3
Copy after login

4. parseInt() removes the decimal point and the part after the decimal point

parseInt(3.141592654) 
// 3
Copy after login

5. Convert the data into Number type

~~3.141592654 
// 3
Copy after login

This article is all over here , for more other exciting content, you can pay attention to the JavaScript Video Tutorial column on the PHP Chinese website!

The above is the detailed content of Introduction to five methods of JavaScript rounding. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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