--- title: Number.toInteger() slug: Web/JavaScript/Reference/Global_Objects/Number/toInteger translation_of: Archive/Web/JavaScript/Number.toInteger ---
{{JSRef("Global_Objects", "Number")}} {{obsolete_header("33")}} {{non-standard_header}}

概览

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

如果参数是 {{jsxref("Global_Objects/NaN", "NaN")}}, {{jsxref("Global_Objects/null", "null")}} 或 {{jsxref("Global_Objects/undefined", "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

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}} Firefox 16 to 32 {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} Firefox 16 to 32 {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also