convert number to the nearest multiple of 10

in javascript, lets say I got a random number 136, i'd like it to convert it automatically to 140 or if I got 124 to 120 etc or 24 to 20 etc..

Answers:

Answer

Divide by 10 and round it, then multiply by 10.

var x = 136;
console.log(Math.round(x / 10) * 10);
Answer

I would just do this: ( Math.round(YourNumber/10) ) * 10

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.