osrec / currencyFormatter.js

A super simple currency formatting library
MIT License
635 stars 61 forks source link

Currencies with different number of units after the decimal place #19

Closed davvidbaker closed 6 years ago

davvidbaker commented 6 years ago

According to ISO 4127, some currencies have a different number of decimal places than the usual 2 digits. For instance, the KRW has 0, while the BHD has 3.

Do you have plans to incorporate these quirks into this library/would you be open to a pull request that does so? Thanks!!

osrec commented 6 years ago

Thanks for the pull request - we will get this merged in a few days - just clearing a backlog of issues!

osrec commented 6 years ago

Just reviewed your pull request, and I'm thinking it might be easier to just maintain a custom set of locales that we map against these currencies, rather than adding all the logic with the mantissa length.

What do you think?

davvidbaker commented 6 years ago

Yeah maybe. I think the more important thing is that the mantissa should be a function of countryCode and not locale, but maybe that isn't something you want this library to do.

osrec commented 6 years ago

ok, had a chat with a few other guys and we agree with you. It should indeed be a function of the currency code, so we'll review and use your changes :)

osrec commented 6 years ago

Ok, we have another swerve ball. Spoke to the original creator of the lib, and it turns out that the locale should indeed drive the currency format, not the currency itself. Why? Because one currency can be formatted differently across different regions (classic example is the Euro). ISO 4217 lists the currencies and the minor units, but not the formats. The standard for currency formats is the CLDR (http://cldr.unicode.org/), which is what the library is based on, however the CLDR can take a bit of time to update.

So we will close this pull request for now, but you did make some important format updates to a number of currencies, which we will include in the next update. Thanks for all the hard work :)