# How to get the value of a number rounded to the nearest integer in JavaScript?

JavascriptWeb DevelopmentFront End Technology

Use the Math.round() method to get the value of a number rounded to the nearest integer.

## Example

You can try to run the following code to return the value of a number rounded to the nearest integer in JavaScript −

<html>
<title>JavaScript Math round() Method</title>
<body>
<script>
var value = Math.round( 0.5 );
document.write("First Test Value : " + value );

var value = Math.round( 20.7 );
document.write("<br />Second Test Value : " + value );

var value = Math.round( 20.3 );
document.write("<br />Third Test Value : " + value );

var value = Math.round( -20.3 );
document.write("<br />Fourth Test Value : " + value );
</script>
</body>
</html>
Published on 16-Feb-2018 07:57:36