源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解

  • 时间:2022-03-23 18:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
首先还是看看JavaScript: The Definitive Guide, 4th Edition中对三个函数的定义。 Math.ceil(): round a number up Arguments: Any numeric value or expression Returns: The closest integer greater than or equal to [i]x[/i]. ----------------------------------------------------------------------------------------------- Math.floor(): round a number down Arguments: Any numeric value or expression Returns: The closest integer less than or equal to [i]x[/i]. ----------------------------------------------------------------------------------------------- Math.round(): round to the nearest integer Arguments: Any number. Returns: The integer closest to [i]x[/i].   以前一直会三个函数的使用产生混淆,现在通过对三个函数的原型定义的理解,其实很容易记住三个函数。 现在做一个总结: 1. Math.ceil()用作向上取整。 2. Math.floor()用作向下取整。 3. Math.round() 我们数学中常用到的四舍五入取整。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部