JavaScript round() Method
Clash Royale CLAN TAG#URR8PPP
<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]-->
JavaScript round() Method
❮ JavaScript Math Object
Example
Round a number to the nearest integer:
Math.round(2.5);
<!--
The result will be:
3
-->Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The round() method rounds a number to the nearest integer.
Note: 2.49 will be rounded down (2), and 2.5 will be rounded up
(3).
Browser Support
Method | |||||
---|---|---|---|---|---|
round() | Yes | Yes | Yes | Yes | Yes |
Syntax
Math.round(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. The number to be rounded |
<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]-->
Technical Details
Return Value: | A number, representing the nearest integer |
---|---|
JavaScript Version: | ECMAScript 1 |
More Examples
Example
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(-2.60);
var e = Math.round(-2.50);
var f = Math.round(-2.49);
<!--
The result of a,b,c,d,e, and f will be:
3
3
2
-3
-2
-2
-->Try it Yourself »
❮ JavaScript Math Object