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.
javascript
const price = 12345.678;
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
console.log(formatter.format(price)); // "$12,345.68"