MaiaVictor
MaiaVictor

Reputation: 53037

How to deal with numbers for finance applications on JavaScript, which lacks an Integer type?

Finance applications demand an integer type due to security reasons. Rounding errors are not acceptable in that kind of application and can lead to exploits. Since JavaScript doesn't offer a proper Integer type, only IEEE 754 Doubles, how do you deal with monetary values in JavaScript, while keeping it safe?

Upvotes: 0

Views: 121

Answers (1)

Patricia Shanahan
Patricia Shanahan

Reputation: 26185

IEEE 754 64-bit binary floating point can represent exactly every integer with magnitude no greater than 2^53. That means you can represent exactly, as an integer number of cents, every money amount with magnitude no greater than $90,071,992,547,409.92. For comparison, the US National Debt is currently about $16,787,451,118,147.

Upvotes: 2

Related Questions