Hacker News new | ask | show | jobs
by evil-olive 1780 days ago
the maximum safe integer in JS is 2^53 - 1. [0]

if you can find a way to use only integers within that range, you can do it safely in plain JS.

for example, units of integer microdollars (one millionth of a dollar) allows you to deal in amounts up to $9 billion without exceeding the safe integer limit. if you want a larger range than that, you need to make a corresponding reduction in precision (such as using millidollars).

or, switch to a full-blown bignum / arbitrary precision library.

0: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...