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.95k stars 528 forks source link

Fetch currency by ISO code #96

Open skwee357 opened 9 years ago

skwee357 commented 9 years ago

Usually when working with accounting / financial data, you already have the amount and currency ISO code stored in the database, for example "100 USD" or "250.90 EUR". I'd like to have a functionality like:

accounting.formatMoney(1250.90, "USD");

Which will output: $ 1,250.90 There is already a currency json list https://gist.github.com/brickcap/43681dadc0b6c91ec0b8 All you need to do cache them inside the plugin and retrieve the symbol by ISO code.

I use accountingjs with handlebars, and I've made a handelbars helper:

formatMoney: function (amount, currency) {
    var symbol = (currency in currencies) ? currencies[currency].symbol : 'N/A';
    return accounting.formatMoney(amount, symbol);
}

Wondering if it is possible and needed to make such functionality as the core of the plugin.

forestbelton commented 9 years ago

:+1: to this, would be pretty useful for us

leonfs commented 9 years ago

+1

Dmitra commented 8 years ago

+1 consider https://github.com/dulaccc/currency-symbol.js

jrencz commented 8 years ago

AFAIK there are no distinction between symbol ($) and ISO code (USD). In docs they are used interchangeably, but they are obviously not the same. ISO codes are especially important for analytic services. By choosing to use ISO codes I break the view. By choosing to use symbol I have to handle the symbol to ISO code mapping myself (which should be handled by money-handling library)

And there's also an ISO number (integer) that described the currency.

https://github.com/RubyMoney/money gets the topic of symbol and ISO right