How to round a number up to the nearest 10 in JavaScript

1 Answer

0 votes
function roundUpToNearest10(num) {
    return Math.ceil(num / 10) * 10;
}
 
console.log(roundUpToNearest10(33)); 
console.log(roundUpToNearest10(59)); 
console.log(roundUpToNearest10(599.99));
console.log(roundUpToNearest10(3.14)); 
console.log(roundUpToNearest10(2)); 
console.log(roundUpToNearest10(19)); 
console.log(roundUpToNearest10(-12));
console.log(roundUpToNearest10(-101)); 
console.log(roundUpToNearest10(-109));
 
   
   
   
/*
   
run:
   
40
60
600
10
10
20
-10
-100
-100
   
*/

 



answered Jun 7, 2022 by avibootz
edited Jun 7, 2022 by avibootz

Related questions

1 answer 203 views
1 answer 214 views
1 answer 200 views
1 answer 192 views
1 answer 206 views
1 answer 187 views
...