I have some code that changes the currency on the page from one to another but the problem is it is not showing currency signs and not taking decimal points. check the code below.Does any one know how to use currency sign and currency in decimal like($12.45) in the code below:
var prices = [
1500,
2000,
342
];
var rates = {
USD: 1, // obviously
EUR: 0.86
}
function updatePrices(rate) {
var elements = document.getElementsByClassName("price");
prices.forEach((price, index) => {
elements[index].innerHTML = price * rate
});
}
document.getElementById("selector").onchange = function () {
updatePrices(rates[this.value]);
}
updatePrices(rates.USD);
<div class="row">
<div class="input-field col s1">
<select id="selector">
<option value="USD" selected>USD</option>
<option value="EUR">EUR</option>
</select>
<label>Currency</label>
</div>
</div>
<ul class="currencies">
<li class="price"></li>
<li class="price"></li>
<li class="price"></li>
</ul>