[removed] Rounding Down in .5 Cases

前端 未结 4 2009
借酒劲吻你
借酒劲吻你 2020-12-19 05:08

I am in a situation where a JavaScript function produces numbers, such as 2.5. I want to have these point five numbers rounded down to 2, rather t

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 05:30

    do this:

    var result = (num - Math.Floor(num)) > 0.5 ? Math.Round(num):Math.Floor(num);
    

提交回复
热议问题