JavaScript Math method: round()
[this page | pdf | back links]
The round() method (of the Math object)
rounds a real number to the nearest integer.
It
has the following syntax with the following parameters:
Math.round(x)
Parameter
|
Required / Optional
|
Description
|
x
|
Required
|
Input parameter
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var c = 4.3;
document.getElementById("Example").innerHTML =
'var x = Math.round(' + c + ')';
document.getElementById("Result").innerHTML = Math.round(c);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodMathRound() {
var z = 12.5; return !!Math.round(z);
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Numbers and Math