js中Math.floor(),Math.round(),Math.ceil()

 时间:2024-10-12 22:37:45

1、Math.floor() ,Math.round()方法执行的是取整计算,它们得到的是与之最接近的整数当参数没有的时候,返回你NaNMath.floor()NaNMath.round()NaN

js中Math.floor(),Math.round(),Math.ceil()js中Math.floor(),Math.round(),Math.ceil()

2、我们再使用Math.floor()传入其它参数看看,如下所示。可以看出返回的都是比它小的,最接近它的整数Math.floor(2.9)2Math.floor(-2.9)-3Math.floor(-0.5)-1Math.floor(-0.9)-1Math.floor(0.9)0Math.floor(1.9)1

js中Math.floor(),Math.round(),Math.ceil()

3、Math.round() 方法可把一个数字四舍五入为最接近的墙绅褡孛数。可以看出Math.round(),的使用和我们平时使用的四舍五入类似,它返回的是最接近它的整数Math.round(1.2)1Math.round(1.6)2Math.round(-1.6)-2Math.round(0.9)1Math.round(0.49)0Math.round(0.01)0Math.round(-0.01)-0Math.round(-0.4)-0

js中Math.floor(),Math.round(),Math.ceil()

4、ceil() 方法是向上取整计算,它返回的是大于或等于参数的整数数据同样Math.ceil()没传入参数也是返回NaNMath.ceil()NaN

js中Math.floor(),Math.round(),Math.ceil()

5、ceil猾诮沓靥() 方法是向上取整计算,它和floor其实刚好相反,下面我们传入一些参数来看看该方法,可以看出返回的都是比它大的,最接近它的整数Math.ceil()NaNMath.c髫潋啜缅eil(1.2)2Math.ceil(-1.2)-1Math.ceil(22.10)23Math.ceil(77.10)78Math.ceil(76.9999)77Math.ceil(-76.9999)-76

js中Math.floor(),Math.round(),Math.ceil()
  • 如何使用PPT做出闪电动画效果
  • 【网络画板】不同样式的格子阵动画
  • Flash中如何用按钮控制图形运动
  • flash 取景框制作
  • 如何利用PPT设置碎裂文字效果
  • 热门搜索
    肉刺怎么去除 怎么下载字体 儿童发型女 笔陡的近义词 青岛海军博物馆 风热感冒症状 纹理烫怎么打理 记号笔怎么擦 喧嚣的近义词 卷心菜怎么炒