xiaoyao-blog

方法一:向上取整Math.ceil();
举例:Math.ceil(11.4)=12; Math.ceil(-11.6)=-11;

方法二:向下取整Math.floor();
举例:Math.floor(11.7)=11;Math.floor(-11.2)=-12;

方法三:四舍五入Math.round();
顾名思义,四舍五入后取整,其算法为Math.round(x+0.5),即原来的数字加上0.5后再想下取整即可。
举例:Math.round(11.5)=12;
Math.round(-11.5)=-11;
————————————————
版权声明:本文为CSDN博主「maple_fix」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/maple_fix/article/details/78656152

分类:

技术点:

相关文章:

  • 2021-12-28
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-11-23
相关资源
相似解决方案