format amount in javascript
const formatToCurrency = amount => {
return "$" + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&,");
};
formatToCurrency(12.34546); //"$12.35"
formatToCurrency(42345255.356); //"$42,345,255.36
format amount in javascript
const formatToCurrency = amount => {
return "$" + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&,");
};
formatToCurrency(12.34546); //"$12.35"
formatToCurrency(42345255.356); //"$42,345,255.36
javascript format number as currency
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
})
formatter.format(1000) // "$1,000.00"
formatter.format(10) // "$10.00"
formatter.format(123233000) // "$123,233,000.00"
float to currency js
function floatToEuro(float){
var euroCurrency
euroCurrency = '\u20AC' + float.toLocaleString('nl-NL',{minimumFractionDigits: 2});
console.log(euroCurrency);
return euroCurrency;
};
javascript currency converter
const select = document.querySelectorAll('.currency');
const number = document.getElementById("number");
const output = document.getElementById("output");
fetch('https://api.frankfurter.app/currencies').then((data) => data.json())
.then((data) => {
display(data);
});
function display(data) {
const entries = Object.entries(data);
for (var i = 0; i < entries.length; i++) {
select[0].innerHTML += `<option value="${entries[i][0]}">${entries[i][0]} : ${entries[i][1]}</option>`;
select[1].innerHTML += `<option value="${entries[i][0]}">${entries[i][0]} : ${entries[i][1]}</option>`;
}
}
function updatevalue() {
let currency1 = select[0].value;
let currency2 = select[1].value;
let value = number.value;
if (currency1 != currency2) {
convert(currency1, currency2, value);
} else {
alert("Choose Diffrent Currency");
}
}
function convert(currency1, currency2, value) {
const host = "api.frankfurter.app";
fetch(`https://${host}/latest?amount=${value}&from=${currency1}&to=${currency2}`)
.then((val) => val.json())
.then((val) => {
console.log(Object.values(val.rates)[0]);
output.value = Object.values(val.rates)[0];
});
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us