Truncate/round whole number in JavaScript?

前端 未结 6 1029
长发绾君心
长发绾君心 2020-12-24 00:11

For a script I\'m writing, I need display a number that has been rounded, but not the decimal or anything past it. I\'ve gotten down to rounding it to the third place, but I

6条回答
  •  Happy的楠姐
    2020-12-24 00:59

    Use Math.floor():

    var f = 20.536;
    var i = Math.floor(f);  // 20
    

    http://jsfiddle.net/J4UVV/1/

提交回复
热议问题