For a limited time, we will throw in BigInteger support at no extra charge!
If this is a problem for you:
node> 0.1 + 0.2 0.30000000000000004
Number (IEEE-754 float) type. Decimal did not make the cut in the new ECMAScript standards so it’s time we got our act together.
BigDecimal works in the browser and in Apache CouchDB. See the simple BigDecimal Couch app demo to compare server-side and client-side expression evaluation.
BigDecimal is available in the NPM repository for NodeJS.
npm install bigdecimal
Now use it normally. It is exactly like the Java 1.5
BigDecimal API. See the BigDecimal documentation for information.
var bigdecimal = ;var i = "1234567890abcdefghijklmn" 24;console;// Output: i is 60509751690538858612029415201127var d = i;var x = "123456.123456789012345678901234567890";console;// Output: d * x = 7470299375046812977089832214047022056.555930270554343863089286012030var two = '2';console;// Output: Average = 30254875845269429306014707662291.561728394506172839450617283945var down = bigdecimalRoundingMode;console;// Output: d / x (25 decimal places) = 490131635404200348624039911.8662623025579331926181155
There is also a command-line REPL tool for experimentation,
bigdecimal.js if you install with the
-g switch, or
./node_modules/.bin/bigdecimal.js otherwise. The
bigdecimal module is already loaded, also available as
BD for convenience.
bigdecimal.js BigDec> d = new BD.BigDecimal("123456.123456789012345678901234567890")
- The implementation is mature, optimized, and maintained by Apache and Google
- The API is well-known, compatible with the J2SE
If you can’t stand the idea of running machine-generated code, please implement
Download Source button at the top and choose a
vX.Y tag. The built code will be in
To build BigDecimal yourself from source, follow these steps:
- Download the GWT SDK, version 2.4.0. Extract it in this checkout, as
- Get Apache Ant if you don't have it (try just running
antat the command line). I just unpack it in this checkout and add
As with the prebuilt download, the CommonJS module will be in