js 的数学处理方法

1、javascript取整方法floor、round、ceil

  floor向下取整:  

Math.floor(0.20); // 0
Math.floor(0.90); // 0
Math.floor(-0.90); // -1
Math.floor(-0.20); // -1

  round四舍五入

Math.round(0.2) // 0
Math.round(0.9) // 1
Math.round(-0.9) // -1
Math.round(-0.2) // 0

  ceil向上取整

Math.ceil(0.2) // 1
Math.ceil(0.9) // 1
Math.ceil(-0.9) // 0
Math.ceil(-0.2) // 0

 


posted @ 2017-12-13 14:05  adouwt  阅读(129)  评论(0编辑  收藏  举报