This is an archived page. It's not actively maintained.


Obsolete since 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.

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

El mètode Number.toInteger() evaluava el valor passat com a paràmetre i el convertia en un nombre sencer, aquest mètode, però, ha sigut eliminat.

Si el valor és NaN, null o bé undefined, es retorna 0. Si el valor és false, es retorna 0 mentre que si el valor és true, es retorna 1.




El valor a convertir-se en un nombre sencer.


Utilitzar toInteger

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


Number.toInteger() era part de l'esborrany de l'especificació de l'ECMAScript 6, però el 23 d'agost de 2013 es va eliminar a la revisió 17 de l'esborrany.

Compatibilitat amb navegadors

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!
Característica Chrome Firefox (Gecko) Internet Explorer Opera Safari
Suport bàsic No support No support [1] No support No support No support
Característica Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Suport bàsic No support No support No support [1] No support No support No support

[1] Aquesta característica va estar suportada des del Firefox 16 al 32.

Vegeu també