How to use the round in JavaScript

In this article we will discuss about how to use the round() method in JavaScript.
  • 1658

This is is the most important method of Math Object in JavaScript. This method returns the round of value to the nearest integer. Here is the following syntax to use this function which is as follows:

Syntax:

Math.round(y);

Here y is the number given to it of which a round of value will be find out.

JavaScript Code:

<html>

<head>

    <title>JavaScript Math round() Method</title>

</head>

<body>

    <script type="text/javascript">

 

        var roundvalue = Math.round(0.7);

        document.write("First Test Value : " + roundvalue

);

 

        var roundvalue = Math.round(21.8);

        document.write("<br />Second Test Value : " +

roundvalue);

 

        var roundvalue = Math.round(50.3);

        document.write("<br />Third Test Value : " +

roundvalue);

 

        var roundvalue = Math.round(-10.2);

        document.write("<br />Fourth Test Value : " +

roundvalue);

    </script>

</body>

</html>

Output:

 java5.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.