Math.round()

In this chapter you will learn:

  1. How to use Math.round()

round method

The Math.round() method is a standard round function. Math.round() rounds up if the number is at least halfway to the next integer value (0.5 or higher) and rounds down if not.

<!DOCTYPE html><!-- ja  v  a  2  s . com-->
<html>
<head>
    <script type="text/javascript">
        document.writeln(Math.round(25.9)); //26 
        document.writeln(Math.round(25.5)); //26 
        document.writeln(Math.round(25.1)); //25 

    </script>
</head>
<body>
</body>
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. How to use Math random method
  2. How to get a random number in a range
  3. How to get a random value from an array
Home » Javascript Tutorial » Math
Math Object
Math min() and max()
Math.ceil()
Math.floor()
Math.round()
Math.random