JavaScript math round() method

The JavaScript math round() method is used to get the closest integer value of a number.
Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Math.round(n)
Math.round(n)
Math.round(n)

Parameters
n: It represents the number whose closest integer value has to be got.

Returns
Closest integer value of a number.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(Math.round(45.7864));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> document.writeln(Math.round(45.7864)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(Math.round(45.7864));
</script>
</body>
</html>