Home  >  Article  >  Web Front-end  >  Introduction to five methods of JavaScript rounding

Introduction to five methods of JavaScript rounding

不言
不言forward
2019-03-26 10:19:076746browse

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

2. Math.ceil() rounds up

Math.floor(3.141592654) 
// 4

3. Math.round() rounds

Math.round(3.141592654) 
// 3

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

parseInt(3.141592654) 
// 3

5. Convert the data into Number type

~~3.141592654 
// 3

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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete