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

1 Answer

0 votes
function roundUpToNearest100(num) {
  	return Math.ceil(num / 100) * 100;
}
 
console.log(roundUpToNearest100(33)); 
console.log(roundUpToNearest100(159)); 
console.log(roundUpToNearest100(599.99));
console.log(roundUpToNearest100(43.14)); 
console.log(roundUpToNearest100(25)); 
console.log(roundUpToNearest100(419)); 
console.log(roundUpToNearest100(-12));
console.log(roundUpToNearest100(-101)); 
console.log(roundUpToNearest100(-199));
 
   
   
   
/*
   
run:
   
100
200
600
100
100
500
0
-100
-100
   
*/

 



answered Jun 7, 2022 by avibootz

Related questions

1 answer 136 views
1 answer 114 views
1 answer 125 views
1 answer 118 views
1 answer 116 views
...