javascript round() method


  Translation results:

英[raʊnd] 美[raʊnd]

adj. Round; arc-shaped; plump, fat; integer

adv. Everywhere; around; roundabout ; in the opposite direction

prep.approximately; around, surrounding; (indicating position) around; nearby

n. circle, circle; cycle; round object, spherical object; (Meeting) One round

vt.& vi. Make a circle; go around; turn around; round...

Third person singular: rounds Plural: rounds present participle : rounding Past tense: rounded Past participle: rounded Comparative: rounder Superlative: roundest

javascript round() methodsyntax

Function: Round a number to the nearest integer.

Syntax: Math.round(x)

Parameters: x Required. Must be a number.​

Return: The integer closest to x.

Note: For 0.5, this method will round up. For example, 3.5 will be rounded to 4, and -3.5 will be rounded to -3.

javascript round() methodexample

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script type="text/javascript">
//不同的数舍入为最接近的整数
    document.write(Math.round(0.60) + "<br />")
    document.write(Math.round(0.50) + "<br />")
    document.write(Math.round(0.49) + "<br />")
    document.write(Math.round(-4.40) + "<br />")
    document.write(Math.round(-4.60))

</script>

</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A