Math. Round, parseint, math. Floor, and math. Ceil decimal points

Source: Internet
Author: User

Math is often seen in the code. round, parseint, and math. although the three functions of floor are known to return an integer at the end of the result, the difference between them is still unclear. Today we will make a summary.

I. Math. Round

Purpose: return the nearest integer. If the fractional part is greater than or equal to 0.5, return the smallest integer greater than the parameter. Otherwise, return the maximum integer smaller than or equal to the parameter.

For example:

Math. Round (5.57) // return 6

Math. Round (2.4) // returns 2

Math. Round (-1.5) // return-1

Ii. parseint

Purpose: parse a string and return an integer, which can be simply understood as the integer after returning the decimal part of the parameter.

For example:

Parseint (5.57) // returns 5

Parseint (2.4) // returns 2

Parseint (-1.5) // returns-1

3. Math. Floor

Purpose: return the maximum integer smaller than or equal to the parameter.

For example:

Math. Floor (5.57) // return 5

Math. Floor (2.4) // returns 2

Math. Floor (-1.5) // return-2

4. Math. ceil

Purpose: return the smallest integer greater than or equal to the parameter.

Math. Ceil (5.57) // return 6

Math. Ceil (2.4) // returns 3

Math. Ceil (-1.5) // return-1

 

Math. Round, parseint, math. Floor, and math. Ceil decimal points

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.