Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
p5.js round() function
Next article icon

JavaScript Math.round( ) function

Last Updated : 22 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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

Syntax:

Math.round(value)

Parameters:

  • value: The number to be rounded to its nearest integer.

Example 1: Rounding Off a number to its nearest integer

To round off a number to its nearest integer, the math.round() function should be implemented in the following way: 

Javascript




let round = Math.round(5.8);
console.log("Number after rounding : " + round);
 
 

Output:

Number after rounding : 6

Example 2: Rounding Off a negative number to its nearest integer

The Math.round() function itself rounds off a negative number when passed as a parameter to it. To round off a negative number to its nearest integer, the Math.round() function should be implemented in the following way: 

Javascript




let round = Math.round(-5.8);
console.log("Number after rounding : " + round);
 
 

Output:

Number after rounding : -6

Example 3: Math.round() function, when a parameter has “.5” as a decimal

Below program shows the result of Math.round() function when the parameter has “.5” as a decimal. 

Javascript




let round = Math.round(-12.5);
console.log("Number after rounding : " + round);
let round2 = Math.round(12.51);
console.log("Number after rounding : " + round2);
 
 

Output:

Number after rounding : -12 Number after rounding : 13

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Opera 3 and above
  • Safari 1 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.



Next Article
p5.js round() function

A

AyushSaxena
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-math

Similar Reads

  • JavaScript Math.ceil( ) function
    The JavaScript Math.ceil() function rounds a given number up to the nearest integer. It always rounds towards positive infinity, meaning it increases the number to the next whole number if it's not already an integer. This function is useful for rounding up values in calculations. SyntaxMath.ceil(va
    2 min read
  • Less.js Math round() Function
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is an extension to normal CSS which basically enhances the abilities of normal CSS and gives superpowers to it. LESS.js provides the built-in Math function that
    3 min read
  • JavaScript Math fround( ) Method
    The Javascript Math.fround() method is used to return the nearest 32-bit single-precision float representation of a number. The Math.fround() method in JavaScript is also used to cast the 64-bit float to a 32-bit float. Syntax: Math.fround(value)Parameters: This method accepts a single parameter val
    2 min read
  • JavaScript Math round() Method
    The JavaScript Math.round() method rounds a number to the nearest integer. It rounds up for decimal values of 0.5 and higher, and down otherwise. Syntax:Math.round(value);Parameters:value: It is the number that you want to round off.Return Value:The Math.round() method returns the value of the given
    3 min read
  • p5.js round() function
    The round() function in p5.js is used to calculate the round value of a number. It calculates the integer closest to the number. Syntax round(number) Parameters: The function accepts only one parameter as mentioned above and described below: number : This parameter stores the number to compute. Belo
    1 min read
  • JavaScript Math floor() Method
    The Math.floor() method in JavaScript is used to round off a number down to the nearest integer, moving towards the lower value. This function is useful when you want to ensure that the result is always rounded down, regardless of whether the number is positive or negative. Syntax Math.floor( value
    2 min read
  • D3.js band.round() Function
    The band.round() function is used to set the round true or false i.e it enables or disables the rounding. If the round is et to true then the start and stop of each band will be an integer. Syntax: band.round([round]); Parameters: This function accepts single parameters as given above and described
    2 min read
  • Less.js Math Functions
    In this article, we will see the various Math functions that are provided by Less.js to perform various mathematical functions as per the user's requirements within CSS code only. Less.js (Leaner Style Sheets) is an extension to normal CSS which basically enhances the abilities of normal CSS and giv
    6 min read
  • Gaussian/banker's rounding in JavaScript
    The task is to implement the Gaussian/banker's rounding with the help of JavaScript. Here, few approaches are discussed. Approach 1: Get the d value(which tells the digits to which we need to round off). Calculate the m(pow(10, d)). Then shift the decimal after the digits we want to round off(if d=2
    3 min read
  • Floating point number precision in JavaScript
    The representation of floating points in JavaScript follows the IEEE-754 format. It is a double-precision format where 64 bits are allocated for every floating point. The displaying of these floating values could be handled using these methods: Table of Content Using toFixed() MethodUsing toPrecisio
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences