JavaScript Math.floor () method

Source: Internet
Author: User

Definition and Usage:

The floor () method can be rounded down by a number.

Grammar:

Math.floor (x);

X: The required parameter, which can be any number or expression;

return value:

The integer that is less than or equal to x and closest to X.

Description

The floor () method performs a down-rounding calculation, which returns an integer that is less than or equal to the function parameter and closest to it.

Example code:

1 //In This example, we will use the floor () method on different numbers:2 3<script type= "Text/javascript" >4document.write (Math.floor (0.60) + "<br/>")5document.write (Math.floor (0.40) + "<br/>")6document.write (Math.floor (5) + "<br/>")7document.write (Math.floor (5.1) + "<br/>")8document.write (Math.floor ( -5.1) + "<br/>")9document.write (Math.floor (-5.9))Ten</script> One  A Expected output: -0 -0 the5 -5 --6 --6 +  - Actual effect: +0 A0 at5 -5 --6 --6
Code

JavaScript Math.floor () method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.