MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.45k stars 475 forks source link

feature request: localize numbers #163

Closed c-x closed 3 years ago

c-x commented 3 years ago

Hello,

Would it be possible to add a toLocaleString() function or something similar ?

I have numbers such as 11783.20 which are rendered nicely with trailing zeros with toFixed(2) for example but the left part isn't localized. I would like to render them with spaces, or commas, such as 11,783.20 or 11 783.20 (without loosing the precision). In short, making them human readable :)

I tried various things with the javascript toLocaleString() but it removes the trailing zeros (ex: 11783.20 becomes 11 783.2).

Thanks!

danmarshall commented 3 years ago

Sorry to plug a different library, but d3-format handles this nicely.

magicjeremy commented 3 months ago

any way we can reopen this? would love to have this solved in the library or maybe have docs on how to use another library to format with decimal.js