Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Floating Point Precision

JavaScript numbers use IEEE 754 double-precision binary floating point, so decimal arithmetic can contain small representation errors. Compare results with a tolerance suited to their magnitude instead of relying on strict equality.

How it works

JavaScript Number values use IEEE 754 double-precision binary floating point. Because many decimal fractions cannot be represented exactly in that format, arithmetic may introduce small errors; the suitable comparison tolerance depends on the values' magnitude.

Syntax

Number.EPSILON

Key points

  • JavaScript represents Number values with IEEE 754 double-precision binary floating point.
  • The representation provides 53 bits of precision for numeric values.
  • Number.EPSILON measures the spacing between 1 and the next representable Number.
  • The mantissa width limits how precisely decimal values can be represented.
  • Only integers through the safe-integer boundary are guaranteed exact representation.

Common mistakes

  • Strict equality is unreliable for floating-point results; use a tolerance instead.
  • Number.EPSILON is appropriate mainly around magnitude 1, not as a universal tolerance.
  • A fixed tolerance becomes less suitable as operand magnitude increases.

Example: Compare floating-point values safely

const value = 0.1 + 0.2;
console.log(value); // 0.30000000000000004

const closeEnough = (a, b, tolerance = Number.EPSILON) =>
  Math.abs(a - b) < tolerance;

console.log(closeEnough(value, 0.3)); // true

Binary floating-point arithmetic can produce a result slightly different from the intended decimal value, so compare values using an appropriate tolerance rather than strict equality.

When to use it

Tolerance-based equality

Comparing calculated decimal results

Using Number.EPSILON

Checking whether a result is close to an expected value near 1

Choosing BigInt

Handling integer identifiers beyond the safe range

  • Number
  • Number.EPSILON
  • Number.MAX_SAFE_INTEGER
  • Number.isSafeInteger
  • BigInt

Source: Number.EPSILON - JavaScript | MDN Web Docs. Checked 2026-10-15.