8

Is there a library available in javascript to handle large numbers with accuracy (sort of like what oracle does by storing the number as a string) and allows for operations like add/subtract/multiply/divide/mod/etc ?

Basically I need to add large numbers like 1234567890.1234567890 + 1234567890.987654321 and get a precise result.

Dmitriy Likhten
  • 5,076
  • 7
  • 36
  • 47

2 Answers2

9

As its author, I recommend big.js, 'a small, fast Javascript library for arbitrary-precision arithmetic with decimal numbers'.

MikeM
  • 13,156
  • 2
  • 34
  • 47
2

There's a few BigInt implementations out there, for example:

Layering fixed-point conversion on top of one of them should be pretty easy.

There is also a new decimal type in some implementations, based on a new definition from IEEE 754r — I believe it was part of the (now abandoned) ECMAScript 4 spec, and is carried forward by ECMAScript 3.1/5 and JavaScript 1.9, but I could be wrong on this point.

ephemient
  • 198,619
  • 38
  • 280
  • 391