JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




Math.round() Function


Tutorials Javascript

Topic

Math.round() method in Javascript.
How to round a number to the nearest integer in javascript?



Explanation

Math Function:

Object: Math

Method: Math.round()

Description: This function is used for rounding a number to the nearest integer. For an example we will try to round the log value of 2.

Example for rounding a number:
<script type="text/javascript">
var a=Math.log(2);
document.write('Log of 2 is::'+a);
document.write('</br>');
var b=Math.round(a);
document.write('The rounded value is::'+ b);
</script>
Result:


In the above example,
  • The log value of 2 is actually "0.6931" .
  • Math.round() method is used for rounding the number to the nearest integer ie., "1".






  • A Note
    Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

    Other Links

    web hosting