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