- Skip to main content
- Skip to search
- Skip to select language
- Get MDN Plus
- English (US)

## Math.round()

The Math.round() static method returns the value of a number rounded to the nearest integer.

## Return value

The value of x rounded to the nearest integer.

## Description

## Using round

Specifications, browser compatibility.

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

- Number.prototype.toPrecision()
- Number.prototype.toFixed()
- Math.ceil()
- Math.floor()
- Math.sign()
- Math.trunc()

## JS Reference

Html events, html objects, other references, javascript math.round(), definition and usage.

The Math.round() method rounds a number to the nearest integer.

2.49 will be rounded down (2), and 2.5 will be rounded up (3).

## JavaScript Rounding Functions

## Return Value

Math.round() is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

## COLOR PICKER

Get certified by completing a course today!

## Report Error

## Your Suggestion:

Your message has been sent to W3Schools.

## Top Tutorials

Top references, top examples, web certificates, get certified.

## A Guide to Rounding Numbers in JavaScript

## JavaScript Rounding

Pro tip: you can also make this assignment in a single line using object destructuring :

## Rounding Numbers in JavaScript with Math.round

To use this method, we simply provide the number we want to round as the argument:

## Rounding Numbers with Math.floor

## Rounding Numbers with Math.ceil

## Rounding Numbers with Math.trunc

Math.ceil returns the same value as Math.trunc when the argument is a negative number:

## Rounding Numbers To Decimal Places in JavaScript

## Rounding to decimal places with Number.toFixed

This can easily be fixed using Number.toFixed :

## Rounding numbers to decimal places with Number.toPrecision

## Problems with Rounding Numbers in JavaScript

## Which Methods Should I Use for Rounding Numbers?

See the Pen SitePoint Rounding by SitePoint ( @SitePoint ) on CodePen .

With all these different methods available, you should have no problem rounding numbers from now on.

If you found this article useful, you may also like these:

## Rounding and truncating numbers in JavaScript

Published: 2016.01.19 · 4 minutes read

5 or more? Raise the Score. 4 or less? Let it Rest.

## Rounding vs Truncating

## Rounding numbers in Javascript

- Math.round() - rounds to the nearest integer (if the fraction is 0.5 or greater - rounds up)
- Math.floor() - rounds down
- Math.ceil() - rounds up

## Truncating numbers in Javascript

## TLTR (too long to read)

I know, I know - time is money. Lets sum it up.

- Math.round() - rounds to the nearest integer
- Math.floor() - rounds down towards negative infinity
- Math.ceil() - rounds up towards positive infinity
- Math.trunc() - rounds up or down towards zero (bad browsers support)

Did you like it? Please share it with your friends or get me a beer coffee. Thanks!

See which is faster for yourself here. :) http://jsperf.com/bitwise-v...

Thanks a lot again. I just updated article and applied all your suggestions.

https://github.com/pawelgrz...

I will fix the link. Thanks for pointing this one out and sharing your results!

Math.round( 3.66666 * 100 ) / 100

Check the speeds: http://jsperf.com/tofixed-p...

Thank you very much! I'm glad that you found it useful.

toFixed is unreliable for rounding. Try this:

1.265.toFixed( 2 ) parseFloat( 1.265.toFixed( 2 ) )

return number > 0 ? Math.round(number) : Math.sign(number) * Math.round(Math.abs(number)); }

Hi I have a problem with JavaScript

I have currency value 11.26 --I need always roundup ---12

If I have 12.56 I need roundup 13.

This is exactly what Math.ceil() is doing.

Someone didn't read a word of this post :P

How can I change 9.26 to 9.27 using math.round ?

var truncated = number - number % 1;

https://t.co/sO86kEe3uX?Vqkugn

https://t.co/yc6wKCq1xP?cjg...

Nice This is and i have used this in my javascript code

I am glad it helped you out :)

## Leave a comment

## JS Loops/Conditionals

## JS String Methods

- codePointAt
- fromCharCode
- fromCodePoint
- lastIndexOf
- localeCompare
- toLocaleLowerCase
- toLocaleUpperCase
- toLowerCase
- toUpperCase

## JS Number Methods

- isSafeInteger
- MAX_SAFE_INTEGER
- MIN_SAFE_INTEGER
- NEGATIVE_INFINITY
- POSITIVE_INFINITY
- toExponential
- toLocaleString
- toPrecision

## JS Math Functions

## JavaScript: Math round() function

## Description

In JavaScript, the syntax for the round() function is:

## Parameters or Arguments

Let's take a look at an example of how to use the round() function in JavaScript.

In this example, we have invoked the round() function using the Math class.

The following will be output to the web browser console log :

The second output to the console log returned 8 which is 8.1 rounded to the nearest integer.

Home | About Us | Contact Us | Testimonials | Donate

While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy .

Copyright © 2003-2023 TechOnTheNet.com. All rights reserved.

- Data Structure & Algorithm Classes (Live)
- System Design (Live)
- DevOps(Live)
- Explore More Live Courses
- Interview Preparation Course
- Data Science (Live)
- GATE CS & IT 2024
- Data Structure & Algorithm-Self Paced(C++/JAVA)
- Data Structures & Algorithms in Python
- Explore More Self-Paced Courses
- C++ Programming - Beginner to Advanced
- Java Programming - Beginner to Advanced
- C Programming - Beginner to Advanced
- Android App Development with Kotlin(Live)
- Full Stack Development with React & Node JS(Live)
- Java Backend Development(Live)
- React JS (Basic to Advanced)
- JavaScript Foundation
- Complete Data Science Program(Live)
- Mastering Data Analytics
- CBSE Class 12 Computer Science
- School Guide
- All Courses
- Linked List
- Binary Tree
- Binary Search Tree
- Advanced Data Structure
- All Data Structures
- Asymptotic Analysis
- Worst, Average and Best Cases
- Asymptotic Notations
- Little o and little omega notations
- Lower and Upper Bound Theory
- Analysis of Loops
- Solving Recurrences
- Amortized Analysis
- What does 'Space Complexity' mean ?
- Pseudo-polynomial Algorithms
- Polynomial Time Approximation Scheme
- A Time Complexity Question
- Searching Algorithms
- Sorting Algorithms
- Graph Algorithms
- Pattern Searching
- Geometric Algorithms
- Mathematical
- Bitwise Algorithms
- Randomized Algorithms
- Greedy Algorithms
- Dynamic Programming
- Divide and Conquer
- Backtracking
- Branch and Bound
- All Algorithms
- Company Preparation
- Practice Company Questions
- Interview Experiences
- Experienced Interviews
- Internship Interviews
- Competitive Programming
- Design Patterns
- System Design Tutorial
- Multiple Choice Quizzes
- Go Language
- Tailwind CSS
- Foundation CSS
- Materialize CSS
- Semantic UI
- Angular PrimeNG
- Angular ngx Bootstrap
- jQuery Mobile
- jQuery EasyUI
- React Bootstrap
- React Rebass
- React Desktop
- React Suite
- ReactJS Evergreen
- ReactJS Reactstrap
- BlueprintJS
- TensorFlow.js
- English Grammar
- School Programming
- Number System
- Trigonometry
- Probability
- Mensuration
- Class 8 Syllabus
- Class 9 Syllabus
- Class 10 Syllabus
- Class 8 Notes
- Class 9 Notes
- Class 10 Notes
- Class 11 Notes
- Class 12 Notes
- Class 8 Maths Solution
- Class 9 Maths Solution
- Class 10 Maths Solution
- Class 11 Maths Solution
- Class 12 Maths Solution
- Class 7 Notes
- History Class 7
- History Class 8
- History Class 9
- Geo. Class 7
- Geo. Class 8
- Geo. Class 9
- Civics Class 7
- Civics Class 8
- Business Studies (Class 11th)
- Microeconomics (Class 11th)
- Statistics for Economics (Class 11th)
- Business Studies (Class 12th)
- Accountancy (Class 12th)
- Macroeconomics (Class 12th)
- Machine Learning
- Data Science
- Mathematics
- Operating System
- Computer Networks
- Computer Organization and Architecture
- Theory of Computation
- Compiler Design
- Digital Logic
- Software Engineering
- GATE 2024 Live Course
- GATE Computer Science Notes
- Last Minute Notes
- GATE CS Solved Papers
- GATE CS Original Papers and Official Keys
- GATE CS 2023 Syllabus
- Important Topics for GATE CS
- GATE 2023 Important Dates
- Software Design Patterns
- HTML Cheat Sheet
- CSS Cheat Sheet
- Bootstrap Cheat Sheet
- JS Cheat Sheet
- jQuery Cheat Sheet
- Angular Cheat Sheet
- Facebook SDE Sheet
- Amazon SDE Sheet
- Apple SDE Sheet
- Netflix SDE Sheet
- Google SDE Sheet
- Wipro Coding Sheet
- Infosys Coding Sheet
- TCS Coding Sheet
- Cognizant Coding Sheet
- HCL Coding Sheet
- FAANG Coding Sheet
- Love Babbar Sheet
- Mass Recruiter Sheet
- Product-Based Coding Sheet
- Company-Wise Preparation Sheet
- Array Sheet
- String Sheet
- Graph Sheet
- ISRO CS Original Papers and Official Keys
- ISRO CS Solved Papers
- ISRO CS Syllabus for Scientist/Engineer Exam
- UGC NET CS Notes Paper II
- UGC NET CS Notes Paper III
- UGC NET CS Solved Papers
- Campus Ambassador Program
- School Ambassador Program
- Geek of the Month
- Campus Geek of the Month
- Placement Course
- Testimonials
- Student Chapter
- Geek on the Top
- Geography Notes
- History Notes
- Science & Tech. Notes
- Ethics Notes
- Polity Notes
- Economics Notes
- UPSC Previous Year Papers
- SSC CGL Syllabus
- General Studies
- Subjectwise Practice Papers
- Previous Year Papers
- SBI Clerk Syllabus
- General Awareness
- Quantitative Aptitude
- Reasoning Ability
- SBI Clerk Practice Papers
- SBI PO Syllabus
- SBI PO Practice Papers
- IBPS PO 2022 Syllabus
- English Notes
- Reasoning Notes
- Mock Question Papers
- IBPS Clerk Syllabus
- Apply for a Job
- Apply through Jobathon
- Hire through Jobathon
- All DSA Problems
- Problem of the Day
- GFG SDE Sheet
- Top 50 Array Problems
- Top 50 String Problems
- Top 50 Tree Problems
- Top 50 Graph Problems
- Top 50 DP Problems
- Solving For India-Hackthon
- GFG Weekly Coding Contest
- Job-A-Thon: Hiring Challenge
- BiWizard School Contest
- All Contests and Events
- Saved Videos
- What's New ?
- JS-Function
- JS-Generator
- JS-Expressions
- JS-ArrayBuffer
- JS-Tutorial
- Web Development
- Web-Technology

## Related Articles

- Write Articles
- Pick Topics to write
- Guidelines to Write
- Get Technical Writing Internship
- Write an Interview Experience
- HTML | DOM Style transitionDuration Property

## JavaScript Math round() Method

- JavaScript Math floor() Method
- JavaScript Math.ceil( ) function
- JavaScript Math.round( ) function
- How to calculate the number of days between two dates in JavaScript ?
- Compare two dates using JavaScript
- How to compare date part only without comparing time in JavaScript?
- Angular 7 | Introduction
- Angular 8 | Introduction
- How to detect when an @Input() value changes in Angular?
- How to submit form on pressing Enter with Angular 9?
- Angular | keyup event
- How to add input fields dynamically on button click in AngularJS ?
- How to create button dynamically with click event in Angular ?
- jQuery UI Datepicker beforeShowDay Option
- jQuery UI | Date Picker
- How to get parameters from a URL string in PHP?
- Get the full URL in PHP
- PHP | parse_url() Function
- PHP | parse_str() Function
- PHP | strval() Function
- How to convert a string into number in PHP?
- PHP | number_format() Function
- How to get current formatted date dd/mm/yyyy in JavaScript ?
- File uploading in React.js
- Hide elements in HTML using display property
- How to append HTML code to a div using JavaScript ?
- Difference between var and let in JavaScript
- Last Updated : 30 Dec, 2022

Parameters: This method accepts a single parameter as mentioned above and described below

Below is an example of the Math round() Method.

Example: To round off a number to its nearest integer.

## Please Login to comment...

## Improve your Coding Skills with Practice

Start your coding journey now.

## Function round #

Round a value towards the nearest integer. For matrices, the function is evaluated element wise.

## Parameters #

## Learn coding interactively.

- JavaScript abs()
- JavaScript acos()
- JavaScript acosh()
- JavaScript asin()
- JavaScript asinh()
- JavaScript atan()
- JavaScript atan2()
- JavaScript atanh()
- JavaScript cbrt()
- JavaScript ceil()
- JavaScript clz32()
- JavaScript cos()
- JavaScript sin()
- JavaScript tan()
- JavaScript sinh()
- JavaScript cosh()
- JavaScript tanh()
- JavaScript sqrt()
- JavaScript pow()
- JavaScript random()
- JavaScript sign()
- JavaScript trunc()
- JavaScript min()
- JavaScript max()
- JavaScript floor()
- JavaScript round()
- JavaScript fround()
- JavaScript log()
- JavaScript log10()
- JavaScript log1p()
- JavaScript log2()
- JavaScript exp()
- JavaScript expm1()
- JavaScript hypot()

## Related Topics

## JavaScript Math round()

## Math.round() Syntax

The syntax of the Math.round() function is:

round() , being a static method, is called using the Math class name.

## Math.round() Parameters

The Math.round() function takes in:

## Return value from Math.round()

Math.round() returns the value of the number rounded to the nearest integer as follows:

- If the fractional portion > 0.5 , x is rounded to integer with higher absolute value.
- If the fractional portion < 0.5 , x is rounded to integer with lower absolute value.
- If the fractional portion = 0.5 , x is rounded to the next integer in the direction of +∞ .

## Example: Using Math.round()

Note: Math.round() returns 0 for null rather than NaN .

## IMAGES

## VIDEO

## COMMENTS

The Math.round() static method returns the value of a number rounded to the nearest integer.

The Math.round() method rounds a number to the nearest integer. 2.49 will be rounded down (2), and 2.5 will be rounded up (3).

The first method we'll look at is Math.round . This is the most straightforward option, and simply rounds any number with a decimal part to the

Rounding numbers in Javascript# · Math.round() - rounds to the nearest integer (if the fraction is 0.5 or greater - rounds up) · Math.floor() -

In JavaScript, round() is a function that is used to return a number rounded to the nearest integer value. Because the round() function is a static function of

JavaScript Math.round( ) function is used to round the number passed as a parameter to its nearest integer. Syntax: Math.round(value).

The Javascript Math.round() method is used to round a number to its nearest integer. If the fractional part of the number is greater than or

Round a value towards the nearest integer. For matrices, the function is evaluated element wise. Syntax #. math.round(

In this tutorial, we will learn about the JavaScript Math.round() function with the help of examples. The Math.round() function returns the number rounded

Question: How do I round a number to n decimal places? Answer: To round a number in JavaScript, use the Math.round method: Math.round(X); // round X to an