How to round a number down to the nearest 10 in TypeScript

1 Answer

0 votes
function roundDownToNearest10(num : number) : any {
  	return Math.floor(num / 10) * 10;
}

console.log(roundDownToNearest10(22)); 
console.log(roundDownToNearest10(79)); 
console.log(roundDownToNearest10(399.99));
console.log(roundDownToNearest10(5.17)); 
console.log(roundDownToNearest10(3)); 
console.log(roundDownToNearest10(18)); 
console.log(roundDownToNearest10(-14));
console.log(roundDownToNearest10(-1001)); 
console.log(roundDownToNearest10(-1009));

  
  
  
/*
  
run:
  
20 
70 
390 
0 
0 
10 
-20 
-1010 
-1010 
  
*/

 



answered Jun 7, 2022 by avibootz

Related questions

1 answer 121 views
1 answer 106 views
1 answer 111 views
1 answer 130 views
1 answer 132 views
...