currency conversion to locale string js

Solutions on MaxInterview for currency conversion to locale string js by the best coders in the world

showing results for - "currency conversion to locale string js"
Fergus
05 Oct 2020
1var number = 123456.789;
2
3// German uses comma as decimal separator and period for thousands
4console.log(number.toLocaleString('de-DE'));
5// → 123.456,789
6
7// Arabic in most Arabic speaking countries uses Eastern Arabic digits
8console.log(number.toLocaleString('ar-EG'));
9// → ١٢٣٤٥٦٫٧٨٩
10
11// India uses thousands/lakh/crore separators
12console.log(number.toLocaleString('en-IN'));
13// → 1,23,456.789
14
15// the nu extension key requests a numbering system, e.g. Chinese decimal
16console.log(number.toLocaleString('zh-Hans-CN-u-nu-hanidec'));
17// → 一二三,四五六.七八九
18
19// when requesting a language that may not be supported, such as
20// Balinese, include a fallback language, in this case Indonesian
21console.log(number.toLocaleString(['ban', 'id']));
22// → 123.456,789
23
Paula
23 Aug 2018
1var number = 123456.789;
2
3// request a currency format
4console.log(number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }));
5// → 123.456,79 €
6
7// the Japanese yen doesn't use a minor unit
8console.log(number.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }))
9// → ¥123,457
10
11// limit to three significant digits
12console.log(number.toLocaleString('en-IN', { maximumSignificantDigits: 3 }));
13// → 1,23,000
14
15// Use the host default language with options for number formatting
16var num = 30000.65;
17console.log(num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}));
18// → "30,000.65" where English is the default language, or
19// → "30.000,65" where German is the default language, or
20// → "30 000,65" where French is the default language
21