Skip to content

Commit

Permalink
Merge pull request #31 from f3ndot/feature/reference-bignumber.js
Browse files Browse the repository at this point in the history
Mention BigNumber for JavaScript as another library available
  • Loading branch information
brazzy committed Feb 8, 2015
2 parents ba90b0e + 4860087 commit 78449f5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion content/languages/javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
Decimal Types
-------------

The best decimal type for JavaScript seems to be a port of [Java's](/languages/java/) <code>BigDecimal</code> class, which also supports [rounding modes](/errors/rounding/):
One of best decimal type for JavaScript seems to be a port of [Java's](/languages/java/) <code>BigDecimal</code> class, which also supports [rounding modes](/errors/rounding/):

var a = new BigDecimal("0.01");
var b = new BigDecimal("0.02");
var c = a.add(b); // 0.03
var d = c.setScale(1, BigDecimal.prototype.ROUND_HALF_UP);

There is also <code>bignumber.js</code>, which boasts a simpler API, smaller library size, and [more operations per second](http://jsperf.com/bignumber-js-vs-big-js-vs-decimal-js/8) over BigDecimal for JavaScript:

BigNumber.config({ROUNDING_MODE: BigNumber.ROUND_HALF_UP})
var a = new BigNumber("0.01");
var b = new BigNumber("0.02");
var c = a.plus(b); // BigNumber(0.03)
var d = c.toFixed(1); // "0.0"


How to Round
------------
Expand All @@ -36,6 +44,7 @@
Resources
---------
* [BigDecimal for JavaScript](https://github.com/dtrebbien/BigDecimal.js)
* [bignumber.js for JavaScript](https://github.com/MikeMcl/bignumber.js)
* [Core JavaScript Reference](https://developer.mozilla.org/en/JavaScript/Reference)
* [parseFloat()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseFloat)
* [toPrecision()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number/toPrecision)
Expand Down

0 comments on commit 78449f5

Please sign in to comment.