[Chapter 21] Reference: Math.round()
Author: David Flanagan
Date: Fri Aug 29 11:17:57 1997

#

| Chapter 21 JavaScript Reference |

# Math.round() Function

## Name

Math.round() Function---round to the nearest integer

## Availability

Navigator 2.0, Internet Explorer 3.0

## Synopsis

    Math.round(x)

### Arguments

`x`

  Any number or numeric expression

### Returns

The integer closest to `x`.

## Description

`Math.round()` rounds its argument up or down to the nearest integer.

## Bugs

In Navigator 2.0, `Math.round()` did not correctly round very large numbers. The following workaround can be used:

    function my_round(num)
    {
        var fl = Math.floor(num);
        var ce = Math.ceil(num);
        return (fl == ce) ? num :
               ((num - fl) < (num - ce)) ? fl :
               ce;
    }

## See Also

"Math", "Math.ceil()", "Math.floor()"

Math.random() |  | Math.sin()