round()  Math  class method JS Home  <<  JS Reference  <<  Math  <<  round()

Description

Returns the value of the specified number rounded to the nearest integer.

  • Like all class methods round() should be used on the class rather than an instance of the class.

Syntax

Signature Description
Math.round(value)Returns the value of the specified number rounded to the nearest integer.

Parameters

Parameter Description
valueThe value you wish to find the round() of:
  • Fractional numbers are rounded up if they are .5 or greater, otherwise they are rounded down.
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null returns 0.

Examples

The code below displays round() usage.


// Store results in an array.
var roundValues = new Array(6);

roundValues[0] = Math.round(1.49);
roundValues[1] = Math.round(-10.5);
roundValues[2] = Math.round('100.5');
roundValues[3] = Math.round('five');
roundValues[4] = Math.round();
roundValues[5] = Math.round(null);

alert(roundValues);  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Math

Class Properties
E
LN2
LN10
LOG2E
LOG10E
PI
SQRT1_2
SQRT2
Instance Properties
None.
Class Methods
abs()
acos()
asin()
atan()
atan2()
ceil()
cos()
exp()
floor()
log()
max()
min()
pow()
random()
round()
sin()
sqrt()
tan()
Instance Methods Getters
None.
Instance Methods Setters
None.

Statements

Operators