您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月05日 01:15

原创 JavaScript Math.floor() 函数详解

4611 次浏览 读完需要≈ 3 分钟

内容目录

Math.floor()函数用于返回小于或等于指定数字的最大整数,一般称为向下取整

该函数属于JavaScript的内置全局对象Math所有主流浏览器均支持该函数

语法

静态函数Math.floor()的语法如下:

Math.floor( number )

参数

参数 描述
number Number类型指定的数值

返回值

Math.floor()的返回值为Number类型。返回小于或等于参数number的最大整数。

如果参数不是数字,或无法转换为数字,则返回NaN

示例&说明

document.writeln( Math.floor( 3.14 ) );	// 3

document.writeln( Math.floor( -0.501 ) );	// -1

// 如果是整数,则返回其本身
document.writeln( Math.floor( -3 ) );	// -3

// 如果无法转换为数字,则返回NaN
document.writeln( Math.floor( "CodePlayer" ) );	// NaN

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单