Math. In JavaScript ceil() 、Math. floor() 、Math. Understanding of the three functions of round()

First, let's look at the definitions of three functions in javascript: the defining 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, the use of the three functions has always been confused. Now, it is easy to remember the three functions through the understanding of the prototype definitions of the three functions.

Now let's make a summary:

1. Math. Ceil() is used to round up.

2. Math. Floor() is used to round down.

3. Math. Round() is the rounding we often use in mathematics.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>