Add support for different precision currencies
See original GitHub issueNot all currencies have two digits after the decimals. Some have 4 digits after the decimal, some have 0 digits after the decimal, while the majority have 2 digits after the decimal.
It would be nice to have an option for the constructor top specify the precision either as a method, or during creation:
currency(2.51) // 2.51
currency(2.51, 4) // 2.5100, with precision option
or
currency.settings.precision(4)
Although this would change the “global” settings for all currency instances after require
d. It would be nice to set the formatting, decimal, separator, symbol and precision on a per usage basis (I have a site that needs to work in multiple currency formats in NodeJS, and altering the settings currently affects everything)
Many suggest that currencies be stored with 4 digits after the decimal in databases (along with the currency code in use), so maybe switching from 2 digits in the internal native format to 4 digits might also be an option.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (5 by maintainers)
@tmorehouse A long wait, but good news! I have a branch where precision is working. There’s a few breaking changes, which I intend to release as
v1.0.0
soon.currency.settings
is now no longer global. Due to the nature of having multiple currencies running in parallel, it did not make sense to have a global magic settings for all. Unfortunately, if you depend on those global settings you will need to make a few changes before you can try out the latest.Settings are now passed to the currency object as a second parameter, including precision! This allows you to define multiple currencies with whatever precision you want.
I’m still testing changes locally to ensure that I didn’t miss anything significant, but if you have a moment feel free to check out that branch and see if it works for you.
OK… I’ll open a separate issue regarding .valueOf()