PDA

View Full Version : Is it possible to change the script to use EUR?



Hacutie297
07-01-2018, 03:28 AM
Hi

Trust you are all well.

My currency script no longer works as they changed the api on the site for the rates. I have an api with a key, but the base is set to EUR and I'm in ZAR

Your original script was
Code:
<script>jQuery(function($){function commatize(num){num=Math.ceil(num).toString(10).split("").reverse();var n=num.length,i=-1,newnum=[];while(++i<n){!(i%3)&&i&&newnum.push(",");newnum.push(num[i])}return newnum.reverse().join("")}jQuery.fn.currencyrates=function(rates){var base=this.text().replace(/\D/g,"");this.append(['<span class="usd usdsprite ocurtextsprite">$ ',commatize(base*rates.USD),'</span><br><span class="gbp gbpsprite ocurtextsprite"> ',commatize(base*rates.GBP),'</span><span class="eur eurosprite ocurtextsprite"> ',commatize(base*rates.EUR)].join(""))};$.getJSON("http://api.fixer.io/latest?base=ZAR",function(data){$(".divborder.col-md-1 h3:has(span.zar)").each(function(i,z){$(z).currencyrates(data.rates)})})});</script>
http://data.fixer.io/api/latest?acce...R,MXN&format=1

which gives the following:

success true
timestamp 1528194609
base "EUR"
date "2018-06-05"
rates
USD 1.16973
ZAR 14.830536
GBP 0.873718
EUR 1
So is it possible to change the script to use EUR as the base and then work out the other currencies based on the ZAR price??

Thanks in advance

hacutie