Math.fround()
La funció Math.fround()
retorna la representació en coma flotant de precisió simple més propera d'un nombre.
Sintaxi
Math.fround(x)
Paràmetres
x
- Un nombre.
Descripció
Com que fround()
és un mètode estàtic de Math
, sempre s'utilitza com Math.fround()
en comptes de com un mètode d'un objecte Math
creat (Math
no és un constructor).
Exemples
Utilitzar Math.fround()
Math.fround(0); // 0
Math.fround(1); // 1
Math.fround(1.337); // 1.3370000123977661
Math.fround(1.5); // 1.5
Math.fround(NaN); // NaN
Polyfill
El comportament d'aquesta funció pot ser emulat amb la funció següent, si Float32Array
està suportat:
Math.fround = Math.fround || function(x) {
return new Float32Array([x])[0];
};
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math.fround' in that specification. |
Standard | Definició inicial. |
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! (en-US)
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | 38 | 26 (26) | No support | 25 | 7.1 |
Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | No support | ? | (Yes) | No support | No support | 8 |