openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.96k stars 530 forks source link

Add locale support for formatting #73

Open optroodt opened 10 years ago

optroodt commented 10 years ago

I want to be able to format the currency according to a specific locale.

For example, my site is translated in Dutch, English, French and German and the correct rules for formatting an amount in e.g. Euro are:

Dutch (nl-NL): € 10,00 English (en-GB): €10.00 German (de-DE): 10,00 € French (fr-FR): 10,00 €

Of course you could define formats for every locale yourself, to me it makes sense that accounting.js does this for you given a locale.

There is a native function toLocaleString that does this and which might be helpful: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

Babel's format_currency (Python) does the same.

thany commented 10 years ago

Similar to https://github.com/josscrowcroft/accounting.js/issues/74