Summary of Math.Round, parseint, Math.floor and Math.ceil decimal rounding in JS

Source: Internet
Author: User

Math.Round, parseint, Math.floor, and Math.ceil can all return an integer, depending on the difference, see the summary below.

First, Math.Round

Function: Rounding, returning parameter +0.5, rounding down.

Such as:

Math.Round (5.57)//return 6

Math.Round (2.4)//Return 2

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

Math.Round (-5.8)//return-6

Second, parseint

Function: Parses a string and returns an integer, which can be simply understood as the integer that returns the fractional part of the parameter.

Such as:

parseint (5.57)//Return 5

parseint (2.4)//Return 2

parseint (-1.5)//return-1

parseint (-5.8)//Return-5

Third, Math.floor

Function: Returns the largest integer less than or equal to the parameter.

Such as:

Math.floor (5.57)//Return 5

Math.floor (2.4)//Return 2

Math.floor (-1.5)//Return-2

Math.floor (-5.8)//return-6

Iv. Math.ceil

Function: Returns the smallest integer greater than or equal to the parameter

Math.ceil (5.57)//return 6

Math.ceil (2.4)//Return 3

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

Math.ceil (-5.8)//Return-5

Summary of Math.Round, parseint, Math.floor and Math.ceil decimal rounding in JS

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.