Hacker News new | past | comments | ask | show | jobs | submit login
Decimal.js, arbitrary-precision decimal type for JavaScript (github.com/mikemcl)
72 points by goblin89 on Nov 28, 2014 | hide | past | favorite | 4 comments



This is great! Proper support for this has been lacking in the Node world. I recommend json-bignum [1] if you need a Node library for JSON serialization that can handle large numbers. For example, retrieving a JSON-formatted row from Postgres which has int64 or numeric values. It is slower than the native JSON functions though.

1. https://github.com/datalanche/json-bignum

Disclaimer: I wrote json-bignum.


Hoping somebody could explain to me why methods are written like so:

P['absoluteValue'] = P['abs'] = function () { }

instead of

P.absoluteValue = p.abs = function () {}


Indeed. And, interestingly, Decimal.format (alone?) is declared with dot notation[0]. Overall coding style feels relatively consistent so there must be some reasoning behind these decisions.

[0] https://github.com/MikeMcl/decimal.js/blob/master/decimal.js...


Reading the ReadMe.md makes me wish that javascript let you overload / implement operators.

Type looks cool though




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: