1.parseInt:只取整数位
例如:
parseInt(3.7) 取整结果为:3
parseInt(-1.1) 取整结果为:-1

2.Math.floor :向下去整,取大的整数
例如:
Math.floor(3.7) 取整结果为:4
Math.floor(-1.1) 取整结果为:-1


3.Math.ceil :向上去整,取小的整数
例如:
Math.floor(3.7) 取整结果为:3
Math.floor(-1.1) 取整结果为:-2

4.Math.round:四舍五入
例如:
Math.round(3.3) 取整结果为:3
Math.round(3.5) 取整结果为:4
Math.round(3.7) 取整结果为:4
Math.round(-1.3) 取整结果为:-1
Math.round(-1.5) 取整结果为:-1
Math.round(-1.6) 取整结果为:-2

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-08-14
  • 2021-07-06
  • 2021-09-16
  • 2022-12-23
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-06-22
  • 2021-10-10
  • 2022-12-23
相关资源
相似解决方案