--- title: Math.fround() slug: Web/JavaScript/Referencia/Objectes_globals/Math/fround translation_of: Web/JavaScript/Reference/Global_Objects/Math/fround ---
La funció Math.fround()
retorna la representació en coma flotant de precisió simple més propera d'un nombre.
Math.fround(x)
x
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).
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
El comportament d'aquesta funció pot ser emulat amb la funció següent, si {{jsxref("Float32Array")}} està suportat:
Math.fround = Math.fround || function(x) { return new Float32Array([x])[0]; };
Especificació | Estat | Comentaris |
---|---|---|
{{SpecName('ES6', '#sec-math.fround', 'Math.fround')}} | {{Spec2('ES6')}} | Definició inicial. |
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | {{CompatChrome("38")}} | {{CompatGeckoDesktop("26")}} | {{CompatNo}} | {{CompatOpera("25")}} | {{CompatSafari("7.1")}} |
Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | {{CompatNo}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatNo}} | 8 |