Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Really excited to see what possibilities for number handling native BigInt in JavaScript will bring

https://developers.google.com/web/updates/2018/05/bigint



probably none. To handle currency correctly you have to handle rounding to the nearest penny correctly. Computers absolutely SUCK at this, in general. So you need a Decimal library, that can handle decimal numbers. Integers ARE NOT DECIMAL.

IBM has had a solution for a long time: http://speleotrove.com/decimal/

Python uses it: https://docs.python.org/3.5/library/decimal.html

Get a proper decimal library, and then you can devote brain cells to actual problems. The IBM link above includes links to libraries that do it right.


You can also just use the smallest unit and work in cents. The Stripe API does this instead of dealing with decimals.




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

Search: