JS rounding up, rounding down

Source: Internet
Author: User

JS up rounding, down rounding, rounding createtime--2018 April 14 11:31:21author:marydon
//1. Keep only the integer part (discard fractional part)parseint (5.1234);//5//2. Rounding Down (<= the largest integer of the number) and parseint ()Math.floor (5.1234);//5//3. Rounding up (with decimals, integers + 1)Math.ceil (5.1234);//4. Rounding (number of decimal parts)Math.Round (5.1234);//5Math.Round (5.6789);//6//5. Absolute valueMath.Abs (-1);//1//6. Return a larger value in both(Math.max);//2//7. Return the smaller values in both(math.min);//1//random Number (0-1)Math.random ();

About Math.floor () and parseint ()

All two of them are reserved integers only, but may be inaccurate when converted:

Tipping point:

When there are 16 decimal places, and the last decimal is 5 o'clock, the value is the largest integer of the number;

Math.floor (5.9999999999999995);//5

When there are 16 decimal places, and the last decimal is 6 o'clock, the value is the largest integer +1 of the number.

Math.floor (5.9999999999999996);//6

Related recommendations:

Similar articles

JS rounding up, rounding down

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.