美文网首页
Math之ceil、floor、round区别

Math之ceil、floor、round区别

作者: studentliubo | 来源:发表于2021-08-23 23:48 被阅读0次
let a = 1.2
let b = 1.5
let c = 1.8

1、ceil():将小数部分一律取整,向整数位进位 // 向上取整

Math.ceil(a) // 2
Math.ceil(b) // 2
Math.ceil(c) // 2

2、floor():将小数部分舍去 // 向下取整

Math.floor(a) // 1
Math.floor(b) // 1
Math.floor(c) // 1

3、round():四舍五入

Math.round(a) // 1
Math.round(b) // 2
Math.round(c) // 2

相关文章

网友评论

      本文标题:Math之ceil、floor、round区别

      本文链接:https://www.haomeiwen.com/subject/szuriltx.html