How to use Math.round() in Javascript

Description

The Math.round() method is a standard round function. Math.round() rounds up if the number is at least halfway to the next integer value (0.5 or higher) and rounds down if not.

Example


console.log(Math.round(25.9)); //26 
console.log(Math.round(25.5)); //26 
console.log(Math.round(25.1)); //25 

The code above generates the following result.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window