Number.EPSILON

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La propriété Number.EPSILON représente la différence entre le chiffre 1 (un) et la plus petite valeur supérieure à 1 qui peut être représentée par un nombre en JavaScript.

Il n'est pas nécessaire de créer un objet Number pour accéder à cette propriété statique, elle est accessible avec Number.EPSILON.

Exemple interactif

const result = Math.abs(0.2 - 0.3 + 0.1);

console.log(result);
// Expected output: 2.7755575615628914e-17

console.log(result < Number.EPSILON);
// Expected output: true
Attributs de Number.EPSILON
ÉcrivableNon
ÉnumérableNon
ConfigurableNon

Description

La propriété EPSILON vaut environ 2.2204460492503130808472633361816E-16 (ce qui correspond à 2^-52).

Exemple

Tester une égalité mathématique avec un seuil de précision

js
x = 0.2;
y = 0.3;
equal = Math.abs(x - y) < Number.EPSILON;

Prothèse d'émulation (polyfill)

js
if (Number.EPSILON === undefined) {
  Number.EPSILON = Math.pow(2, -52);
}

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-number.epsilon

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
EPSILON

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi

  • L'objet Number auquel appartient cette propriété.