Summing up the method of math rounding

Source: Internet
Author: User

Rounding off Decimal rounding: Math.floor (2) =2
Rounding off Decimal rounding: Math.floor (2.1) =2
Rounding off Decimal rounding: Math.floor (-2.1) =-3
Rounding off Decimal rounding: Math.floor (-2.5) =-3
Rounding off Decimal rounding: Math.floor (2.9) =2
Rounding off Decimal rounding: Math.floor (-2.9) =-3
Summary: Math.floor (x) = largest integer less than x

Rounding off Decimals: Math.ceil (2) =2
Rounding off Decimals: Math.ceil (2.1) =3
Rounding off Decimals: Math.ceil (2.5) =3
Rounding off Decimals: Math.ceil (-2.5) =-2
Rounding off Decimals: Math.ceil (2.9) =3
Rounding off Decimals: Math.ceil (-2.9) =-2
Summary: Math.ceil (x) = smallest integer not less than X

Rounded rounding: Math.Round (3.1) 3
Rounded rounding: Math.Round (3.5) 4
Rounded rounding: Math.Round (-3.1)-3
Rounded rounding: Math.Round (-3.5)-3

Summary: Math.Round (x) = Math.floor (x+0.5) (rounding in mathematical sense)

Rounded rounding: Math.rint (2) =2
Rounded rounding: Math.rint (2.1) =2
Rounded rounding: math.rint (-2.5) =-2
Rounded rounding: math.rint (2.5) =2
Rounded rounding: Math.rint (2.9) =3
Rounded rounding: Math.rint (-2.9) =-3
Rounded rounding: Math.rint (-2.49) =-2
Rounded rounding: Math.rint (-2.51) =-3

Special case: Math.rint ()
1. If the parameter itself is an integer, it returns itself.
2. If it is not a number or infinity or plus or minus 0, the result is itself

Summary: Floor is rounded down, ceil upward, round and rint rounded, rounded with absolute values, and then added with symbols, when encountered. 5. Take even that.


This article is from the "Foreverhela" blog, make sure to keep this source http://feven1994.blog.51cto.com/10602437/1683460

Summing up the method of math rounding

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.