“Fungsi JS Format Uang” Kode Jawaban

JavaScript Format Mata Uang

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

Fungsi JS Format Uang

// 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 */
Uptight Unicorn

Jawaban yang mirip dengan “Fungsi JS Format Uang”

Pertanyaan yang mirip dengan “Fungsi JS Format Uang”

Lebih banyak jawaban terkait untuk “Fungsi JS Format Uang” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya