Data MasterySaturday, January 24, 2026

Numbers & Math

Precision, rounding, and random numbers.

Advertisement

Support JS Fruggal by checking out our sponsors.

JavaScript numbers are floating point. This means they aren't always precise.

The 0.3 Bug

0.1 + 0.2 === 0.30000000000000004
Never compare floats directly. Use Math.abs(a - b) < epsilon.

Handling Money

For money, use the Intl.NumberFormat API. It handles commas, decimals, and currency symbols automatically.

const price = 12345.678;

const formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',
});

console.log(formatter.format(price)); // "$12,345.68"
Advertisement

Support JS Fruggal by checking out our sponsors.