round

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

Applies to

Math

Syntax

round(x)

Parameters

x

A number.

Description

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

round is a static method of Math. As a result, you always use it as Math.round(), rather than as a method of a Math object you create.

Examples

//Displays the value 20
Console.Write("The rounded value is " + Math.round(20.49))

//Displays the value 21
Console.Write("The rounded value is " + Math.round(20.5))

//Displays the value -20
Console.Write("The rounded value is " + Math.round(-20.5))

//Displays the value -21
Console.Write("The rounded value is " + Math.round(-20.51))