yawnsde / MMM-CurrencyExchange

Foreign exchange rates and currency conversion (exchangeratesapi.io)
10 stars 4 forks source link

Inverse on exchange #5

Open BrielC opened 5 years ago

BrielC commented 5 years ago

From my side as well. Its really a great module to have. My country's currency is weaker than the USD and GBP ext. The exchange make better more sense if we see the inverse. This is the way we hear it on radio and the way we understand it. Would it be possible to bring in an inverse option on the answer.

New Answer = 1 / Answer

Currently what i will see on the exchange is GBP = 0.0563 USD = 0.0705

But what i would really love to see is GBP = 17.75 USD = 14.18

This is the cost for me to purchase a USD or GBP Or basically as below:

base: 'GBP', symbol: 'ZAR', base: 'USD', symbol: 'ZAR'

mickecamino commented 5 years ago

I just did this change to have this functionality. I am not that good in programming js, but I learn slowly ` index 556e1f8..58af87a 100644 --- a/MMM-CurrencyExchange.js +++ b/MMM-CurrencyExchange.js @@ -126,7 +126,8 @@ Module.register('MMM-CurrencyExchange',{ }

                    var rateSpan = document.createElement('span');
BrielC commented 5 years ago

Hi Mikael Thanks very much for taking the time to help. I am going to try this over the weekend. Its really much appreciated and i will let you know if it worked Best regards Cobus Briel

mickecamino commented 5 years ago

A more cleaner solution: Add to config.js a new line with inverseRate: true :

  layoutStyle: 'table',
  inverseRate: true,
  initialLoadDelay: 0, // 0 seconds delay
  apiBase: "https://api.exchangeratesapi.io/latest",

In MMM-CurrencyExchange change to the following around line 128 from:

          rateSpan.innerHTML = ((this.config.layoutStyle == 'ticker' && i < (this.rates.length - 1)) ? 1 / this.rates[i].rate + ' &bull; ' : 1 / this.rates[i].rate);
      rateContainer.appendChild(rateSpan);

to:

      if (this.config.inverseRate) {
          inversedrate = 1 / this.rates[i].rate; // Inverse the rate
          rateSpan.innerHTML = ((this.config.layoutStyle == 'ticker' && i < (this.rates.length - 1)) ? inversedrate.toFixed(2) + ' &bull; ' : inversedrate.toFixed(2));
      } else {
          rateSpan.innerHTML = ((this.config.layoutStyle == 'ticker' && i < (this.rates.length - 1)) ? 1 / this.rates[i].rate + ' &bull; ' : 1 / this.rates[i].rate);
      }
      rateContainer.appendChild(rateSpan);
yawnsde commented 5 years ago

@mickecamino Thanks for your solution. I am mostly offline currently, but received a mail notification about your response. Would you mind if I integrate this into the module?

mickecamino commented 5 years ago

@yawnsde Please do integrate it. I decided to use only two decimals in the inversed rate, it should perhaps be a setting in the config.js? Thanks for a great module.

BrielC commented 5 years ago

The module is working now exactly the way i wanted it to. Thanks very much once again for the help and effort. Great start to my weekend :-)

nafanz commented 4 years ago

Please help me figure it out. I want to see how much the dollar and the euro are worth in rubles.

config: { base: 'USD', symbols: ['RUB'] }

Meets my expectations, but:

config: { base: 'RUB', symbols: ['USD', 'EUR'] }

In this case, I see how much 1 ruble costs. As far as I understood from the discussions, adding inverseRate: true should show me how many rubles are 1 dollar and 1 euro, but this does not happen.

BrielC commented 4 years ago

Hi nafanz

There is more code to change than only inverseRate: true

If you give me an email address then i will mail you my *.js file with all the changes. The only additions that i made was to increase the font

Regards

nafanz commented 4 years ago

@BrielC nafanz@mail.ru