Number.toInteger()

已废弃 Gecko 33 (Firefox 33 / Thunderbird 33 / SeaMonkey 2.30)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

非标准
该特性是非标准的,请尽量不要在生产环境中使用它!

概览

Number.toInteger() 用来将参数转换成整数,但该方法的实现已被移除.

如果参数是 undefined, 会返回0 . 如果参数值是true返回1,false的话返回0.

语法

Number.toInteger(number)

参数

number
将被转换成整数的参数.

示例

例子: 使用 toInteger()方法

Number.toInteger(0.1);     // 0
Number.toInteger(1);       // 1
Number.toInteger(Math.PI); // 3
Number.toInteger(null);    // 0

Specifications

  • Number.toInteger() 是ECMAScript 6 起草的一部分, 但在2013-8-23的Draft Rev 17 中被移除 .

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 未实现 Firefox 16 to 32 未实现 未实现 未实现
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未实现 未实现 Firefox 16 to 32 未实现 未实现 未实现

See also