Revision 88057 of Math.round()

• Revision slug: JavaScript/Reference/Global_Objects/Math/round
• Revision title: round
• Revision id: 88057
• Created:
• Creator: Marcoos
• Is current revision? No
• Comment
Tags:

Revision Content

Summary

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

 Method of Math Static Implemented in: JavaScript 1.0, NES 2.0 ECMA Version: ECMA-262

Math.round(x)

x
A number.

Description

If the fractional portion of number is .5 or greater, the argument is rounded to the next higher integer. If the fractional portion of number is less than .5, the argument is rounded to the next lower integer.

Because round is a static method of Math, you always use it as Math.round(), rather than as a method of a Math object you created.

Examples

Example: Using Math.round

//Returns the value 20
x=Math.round(20.49)

//Returns the value 21
x=Math.round(20.5)

//Returns the value -20
x=Math.round(-20.5)

//Returns the value -21
x=Math.round(-20.51)
{{ wiki.languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Math/round" } ) }}

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p>Returns the value of a number rounded to the nearest integer.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Objects/Math">Math</a></td>
</tr>
<tr>
<td colspan="2">
<p><b>Static</b>
</p>
</td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.0, NES 2.0</td>
</tr>
<tr>
<td>ECMA Version:</td>
<td>ECMA-262</td>
</tr>
</tbody></table>
<h3 name="Syntax"> Syntax </h3>
<p><code>
Math.round(<i>x</i>)
</code>
</p>
<h3 name="Parameters"> Parameters </h3>
<dl><dt> <code>x</code> </dt><dd> A number.
</dd></dl>
<h3 name="Description"> Description </h3>
<p>If the fractional portion of <code>number</code> is .5 or greater, the argument is rounded to the next higher integer. If the fractional portion of <code>number</code> is less than .5, the argument is rounded to the next lower integer.
</p><p>Because <code>round</code> is a static method of <code>Math</code>, you always use it as <code>Math.round()</code>, rather than as a method of a <code>Math</code> object you created.
</p>
<h3 name="Examples"> Examples </h3>
<h4 name="Example:_Using_Math.round"> Example: Using <code>Math.round</code> </h4>
<pre>//Returns the value 20
x=Math.round(20.49)

//Returns the value 21
x=Math.round(20.5)

//Returns the value -20
x=Math.round(-20.5)

//Returns the value -21
x=Math.round(-20.51)
</pre>
{{ wiki.languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Math/round" } ) }}