Javascript - Math round() Method

The round() method rounds a number to the nearest integer.

Description

The round() method rounds a number to the nearest integer.

2.49 will be rounded down, 2.5 will be rounded up.

Syntax

Math.round(x)

Parameter Values

Parameter Require Description
x Required. The number to be rounded

Return

A Number, representing the nearest integer

Example

Round a number to the nearest integer:

Demo

//round the number 2.5 to its nearest integer.
console.log(Math.round(2.5));/*from w w  w  .ja  v a 2s.  c om*/

//Round different numbers to the nearest integer:

var a = Math.round(2.60);
var b = Math.round(2.50);
var c = Math.round(2.49);
var d = Math.round(-1.60);
var e = Math.round(-1.50);
var f = Math.round(-1.49);

var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f;
console.log(x);

Result