Round money to nearest 10 dollars in Javascript

后端 未结 5 1426
不思量自难忘°
不思量自难忘° 2021-01-01 11:42

How can I round a decimal number in Javascript to the nearest 10? My math is pretty rubbish today, it could be the 2 hour sleep :/

Some sample cases

5条回答
  •  無奈伤痛
    2021-01-01 12:25

    Use this function:

    function roundTen(number)
    {
      return Math.round(number/10)*10;
    }
    
    
    
    alert(roundTen(2823.66));
    

提交回复
热议问题