- Instant help with your JavaScript coding problems

Round a number in JavaScript

Question:
How to round a number in JavaScript?
Answer:
const num1 = Math.round(5.1);
const num2 = Math.round(5.5);
const num3 = Math.round(5.9);

console.log(num1 + ' / ' + num2 + ' / ' + num3); // 5 - 6 - 6
Description:

The Math.round() function returns the value of a number rounded to the nearest integer.

Share "How to round a number in JavaScript?"