Home > Web Front-end > JS Tutorial > Understanding of the three functions Math.ceil(), Math.floor(), and Math.round() in JavaScipt_Basic knowledge

Understanding of the three functions Math.ceil(), Math.floor(), and Math.round() in JavaScipt_Basic knowledge

WBOY
Release: 2016-05-16 18:28:11
Original
1413 people have browsed it

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.

Related labels:
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