JSFiddle - React, Tailwind, and code Playground
by Wendell Christian
HTML
<p>O valor em real é: <span id="valorreal"></span> BRL<br>
JavaScript
function converterreal(valor){
var moeda = 0;
var valor = valor;
var valorconvertido = 0;
$.ajax({
url: 'https://free.currencyconverterapi.com/api/v6/convert?q=BRL_CNY&compact=ultra&apiKey=873041c527593ec7e31e',
dataType: 'jsonp',
success: function(data) {
moeda = data.BRL_CNY;
console.log(moeda);
valorconvertido = (moeda*valor);
function formata(v){
return parseFloat(v).toLocaleString("pt-BR", { style: "currency" , currency:"BRL"});
}
//document.write(formata(valorconvertido));
$("#valorreal").html(formata(valorconvertido));
}
});
}
var testevalor = converterreal(400);