Math.round(x)  四舍五入 加上0.5向下取整

  Math.round(1.5)  2

  Math.round(-11.5)  -11

  Math.round(-11.2)  -10

Math.ceil(x)  不小于x的最小整数

  Math.ceil(1.5)  2

  Math.ceil(-1.5)  -1

Math.floor(x)  返回小于等于x的最大整数

  Math.floor(5.99))   5
  Math.floor(-5.99)  -6

Math.random()  生成0和1之间的随机小数

  Math.random() * 7 生成0和7之间的随机小数
  Math.random() * 7 + 1生成0和8之间的随机小数
  Math.floor(Math.random() * 7 + 1)生成0和8之间的随机整数,注意是整数,不是小数

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案