Untuk membuat format mata uang dalam javascript biasanya kita membuat sebuah function untuk merubahnya.

Ada alternatif lain sebenarnya dalam membuat format mata uang, misalnya kita menggunakan Obj.toLocaleString.

Sering butuh tapi lupa terus, jadi ini lah contekannya.

Contohnya sebagai berikut

function eArabic(x){
  return x.toLocaleString('ar-EG');

// expected output: "١٢٣٬٤٥٦٫٧٨٩"

// expected output: "123456.789"

// expected output: "ليس رقم"

Hasilnya sebagai berikut

> "١٢٣٬٤٥٦٫٧٨٩"
> "123456.789"
> "ليس رقم"


numObj.toLocaleString([locales [, options]])

untuk lebih jelas bisa lihat di halaman berikut Intl.NumberFormat()

Contoh :

var number = 3500;

console.log(number.toLocaleString()); // Displays "3,500" if in U.S. English locale
function toLocaleStringSupportsLocales() {
  var number = 0;
  try {
  } catch (e) {
    return === 'RangeError';
  return false;
function toLocaleStringSupportsOptions() {
  return !!(typeof Intl == 'object' && Intl && typeof Intl.NumberFormat == 'function');
var number = 123456.789;

// German uses comma as decimal separator and period for thousands
// → 123.456,789

// Arabic in most Arabic speaking countries uses Eastern Arabic digits
// → ١٢٣٤٥٦٫٧٨٩

// India uses thousands/lakh/crore separators
// → 1,23,456.789

// the nu extension key requests a numbering system, e.g. Chinese decimal
// → 一二三,四五六.七八九

// when requesting a language that may not be supported, such as
// Balinese, include a fallback language, in this case Indonesian
console.log(number.toLocaleString(['ban', 'id']));
// → 123.456,789
var number = 123456.789;

// request a currency format
console.log(number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }));
// → 123.456,79 €

// the Japanese yen doesn't use a minor unit
console.log(number.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }))
// → ¥123,457

// limit to three significant digits
console.log(number.toLocaleString('en-IN', { maximumSignificantDigits: 3 }));
// → 1,23,000

// Use the host default language with options for number formatting
var num = 30000.65;
console.log(num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}));
// → "30,000.65" where English is the default language, or
// → "30.000,65" where German is the default language, or
// → "30 000,65" where French is the default language


ar-SA Arabic (Saudi Arabia)
bn-BD Bangla (Bangladesh)
bn-IN Bangla (India)
cs-CZ Czech (Czech Republic)
da-DK Danish (Denmark)
de-AT Austrian German
de-CH "Swiss" German
de-DE Standard German (as spoken in Germany)
el-GR Modern Greek
en-AU Australian English
en-CA Canadian English
en-GB British English
en-IE Irish English
en-IN Indian English
en-NZ New Zealand English
en-US US English
en-ZA English (South Africa)
es-AR Argentine Spanish
es-CL Chilean Spanish
es-CO Colombian Spanish
es-ES Castilian Spanish (as spoken in Central-Northern Spain)
es-MX Mexican Spanish
es-US American Spanish
fi-FI Finnish (Finland)
fr-BE Belgian French
fr-CA Canadian French
fr-CH "Swiss" French
fr-FR Standard French (especially in France)
he-IL Hebrew (Israel)
hi-IN Hindi (India)
hu-HU Hungarian (Hungary)
id-ID Indonesian (Indonesia)
it-CH "Swiss" Italian
it-IT Standard Italian (as spoken in Italy)
ja-JP Japanese (Japan)
ko-KR Korean (Republic of Korea)
nl-BE Belgian Dutch
nl-NL Standard Dutch (as spoken in The Netherlands)
no-NO Norwegian (Norway)
pl-PL Polish (Poland)
pt-BR Brazilian Portuguese
pt-PT European Portuguese (as written and spoken in Portugal)
ro-RO Romanian (Romania)
ru-RU Russian (Russian Federation)
sk-SK Slovak (Slovakia)
sv-SE Swedish (Sweden)
ta-IN Indian Tamil
ta-LK Sri Lankan Tamil
th-TH Thai (Thailand)
tr-TR Turkish (Turkey)
zh-CN Mainland China, simplified characters
zh-HK Hong Kong, traditional characters
zh-TW Taiwan, traditional characters

Comments : To post comment, you must login first using google. No worry, it's safe