

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between Math.ceil() and Math.round() methods in JavaScript?
Math.ceil() and Math.round() methods differ in a way that the former round off a number to its nearest integer in upward direction of rounding(towards the greater value) whereas the latter round off a number to its nearest integer in downward direction of rounding(towards lower value). Let's examine the two methods individually.
Math.ceil()
Math.ceil() method round off number passed as parameter to its nearest integer so as to get greater value.
Example
In the below example when a number 5.34 passed as a parameter, Math.ceil() round off it in to 6, which is a greater value than actual number.
<html> <body> <script> document.write(Math.ceil(5.34)); </script> </body> </html>
Output
6
Math.round()
Math.round() method round off number passed as parameter to its nearest integer so as to get lower value.
Example
In the below example when a number 5.34 passed as a parameter, Math.round() round off it in to 5, which is a lower value than actual number.
<html> <body> <script> document.write(Math.round(5.34)); </script> </body> </html>
Output
5
- Related Questions & Answers
- What is math object in JavaScript?
- Math class methods in C#
- What is Math Object in JavaScript Program?
- What are JavaScript Math Functions?
- Math class methods in Java Programming
- Static import the Math Class Methods in Java
- JavaScript Math Object example
- Math. fround() function in JavaScript
- Math. hypot() function in JavaScript
- What is the difference between functions and methods in JavaScript?
- What is the difference between instanceof() and Array.isArray() methods in JavaScript?
- Math Class in C#
- Java multiplyExact() in Math
- Implementing Math function and return m^n in JavaScript
- Use static Import for sqrt() and pow() methods in class Math in Java