Q:

Write a JavaScript program to round a number to a specified amount of digits

0

Write a JavaScript program to round a number to a specified amount of digits.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);

console.log(round(1.005, 2));
console.log(round(1.05, 2));
console.log(round(1.0005, 2));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now