Math.round()

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE3+, Opera3+ Syntax

							math.round(num)
						

Description

The round() method of the Math object is used to round a number to its nearest integer value. If the fractional portion of the number is .5 or greater, the result is rounded to the next highest integer. If the fractional portion of number is less than .5, the result is rounded to the next lowest integer.

Example

Listing 6.171 shows how the round() method is used.

Listing 6.171 Example of the round() Method
 <html> <body> <script language="JavaScript"> <!–– Hide // function rounds input number to nearest integer function doMath(){ var inputNum1=document.form1.input1.value; var result = Math.round(inputNum1); document.form1.answer.value ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.