First, let’s take a look at the definitions of the three functions in JavaScript: The Definitive Guide, 4th Edition.
Math.ceil(): round a number up
Arguments: Any numeric value or expression
Returns: The closest integer greater than or equal to x.
-------------------------------------------------- ----------------------------------------
Math.floor(): round a number down
Arguments: Any numeric value or expression
Returns: The closest integer less than or equal to x.
-------------------------------------------------- ----------------------------------------
Math.round(): round to the nearest integer
Arguments: Any number.
Returns: The integer closest to x.
In the past, there was always confusion about the use of the three functions. Now through understanding the prototype definitions of the three functions, it is actually easy to remember the three functions.
Now make a summary:
1. Math.ceil() is used to round up.
2. Math.floor() is used to round down.
3. Math.round() Rounding is commonly used in our mathematics.