这三个都是将小数变成整数的函数,但是每一个都有不同的作用:
ceil():将小数部分一律向整数部分进位。
如:
Javascript:三个函数ceil()、floor()、round()的区别 程序代码
Math.ceil(12.2)//返回13
Math.ceil(12.7)//返回13
Math.ceil(12.0)//返回12


floor():一律舍去,仅保留整数。
如:
Javascript:三个函数ceil()、floor()、round()的区别 程序代码
Math.floor(12.2)//返回12
Math.floor(12.7)//返回12
Math.floor(12.0)//返回12


round():进行四舍五入
如:
Javascript:三个函数ceil()、floor()、round()的区别 程序代码
Math.round(12.2)//返回12
Math.round(12.7)//返回13
Math.round(12.0)//返回12

相关文章:

  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案