- Instant help with your JavaScript coding problems

Round a number to the nearest 10 using JavaScript

Question:
How to round a number to the nearest 10 using JavaScript?
Answer:
const num1 = Math.round(11.95 / 10) * 10;
const num2 = Math.round(13.45 / 10) * 10;
const num3 = Math.round(18.05 / 10) * 10;

console.log(num1 + ' - ' + num2 + ' - ' + num3); // 10 - 10 - 20
Description:

To round a number to the nearest 10 you can use the pure JavaScript function Math.round() with an extra division and multiplication.

Share "How to round a number to the nearest 10 using JavaScript?"