Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript format currency

function formatToCurrency(amount){
    return (amount).toFixed(2).replace(/d(?=(d{3})+.)/g, '$&,'); 
}
formatToCurrency(12.34546); //"12.35"
formatToCurrency(42345255.356); //"42,345,255.36"
Comment

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"
Comment

function js format money

// Create our number formatter.
var formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',

  // These options are needed to round to whole numbers if that's what you want.
  //minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
  //maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});

formatter.format(2500); /* $2,500.00 */
Comment

javascript rupiah currency format

const rupiah = (number) => {
	return new Intl.NumberFormat("id-ID", {
		style: "currency",
		currency: "IDR"
	}).format(number);
}
Comment

javascript currency format

const formatter = new Intl.NumberFormat('en-ID', {
  style: 'currency',
  currency: 'IDR'
}).format(10000000)
.replace(/[IDR]/gi, '')
.replace(/(.+d{2})/, '')
.trimLeft()


console.log(`Rp ${formatter}`)
Comment

javascript number format indian currency

(1234567.8).toFixed(2).replace(/(d)(?=(d{2})+d.)/g, '$1,') // "12,34,567.80"
Comment

Javascript number format, currency format

const yourNumber = -100
const nf = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' })
console.log(nf.format(yourNumber))
 Run code snippet
Comment

JS Currency Converter

// include api for currency change
const api = "https://api.exchangerate-api.com/v4/latest/USD";
  
// for selecting different controls
var search = document.querySelector(".searchBox");
var convert = document.querySelector(".convert");
var fromCurrecy = document.querySelector(".from");
var toCurrecy = document.querySelector(".to");
var finalValue = document.querySelector(".finalValue");
var finalAmount = document.getElementById("finalAmount");
var resultFrom;
var resultTo;
var searchValue;
  
// Event when currency is changed
fromCurrecy.addEventListener('change', (event) => {
    resultFrom = `${event.target.value}`;
});
  
// Event when currency is changed
toCurrecy.addEventListener('change', (event) => {
    resultTo = `${event.target.value}`;
});
  
search.addEventListener('input', updateValue);
  
// function for updating value
function updateValue(e) {
    searchValue = e.target.value;
}
  
// when user clicks, it calls function getresults 
convert.addEventListener("click", getResults);
  
// function getresults
function getResults() {
    fetch(`${api}`)
        .then(currency => {
            return currency.json();
        }).then(displayResults);
}
  
// display results after convertion
function displayResults(currency) {
    let fromRate = currency.rates[resultFrom];
    let toRate = currency.rates[resultTo];
    finalValue.innerHTML = 
       ((toRate / fromRate) * searchValue).toFixed(2);
    finalAmount.style.display = "block";
}
  
// when user click on reset button
function clearVal() {
    window.location.reload();
    document.getElementsByClassName("finalValue").innerHTML = "";
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native touchableopacity disable 
Javascript :: empty select option jquery 
Javascript :: js number 2 decimal places 
Javascript :: req.body is undefined 
Javascript :: js get current time minutes 
Javascript :: styling scrollview height in react native 
Javascript :: loop through key value pairs js 
Javascript :: jquery show for 5 seconds 
Javascript :: passport.authenticate inside a controller 
Javascript :: nodejs does every worker thread need a new core 
Javascript :: remove last character javascript 
Javascript :: react native android build apk 
Javascript :: Could not find com.yqritc:android-scalablevideoview:1.0.4 react native video 
Javascript :: select2 onchange 
Javascript :: Javascript track mouse pointer 
Javascript :: sequelize exclude attribute 
Javascript :: tolowercase javascript 
Javascript :: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. 
Javascript :: document.ready 
Javascript :: document on click dynamic element 
Javascript :: update node-modules 
Javascript :: clear ctx canvas with javascript 
Javascript :: get search params from url react 
Javascript :: js method string remove extra spaces 
Javascript :: random password javascript 
Javascript :: show and hide div tag based on checkbox selection using jquery 
Javascript :: js proxy to array 
Javascript :: javascript remove get parameter from url 
Javascript :: separate digits in javascript 
Javascript :: Node.js: printing to console without a trailing newline 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =