Round a float up to the next integer in javascript

前端 未结 4 2095
北海茫月
北海茫月 2020-12-10 00:46

I need to round floating point numbers up to the nearest integer, even if the number after the point is less than 0.5.

For example,

  • 4.3 should be 5 (no
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 01:25

    Use the Math.ceil[MDN] function

    var n = 4.3;
    alert(Math.ceil(n)); //alerts 5
    

提交回复
热议问题