3

Looking for solution to get full currency value including pennies. numberingSystem: 'fullwide' coming with letter spacing when getting full digits. Is there any option to get full digit with currency code in NumberFormat() ?

Expected behaviour: €56.123456

const CurrencyFormat = (amount = 0, currency = 'eur', digitLength = 'latn') => {
  return new Intl.NumberFormat('en-GB', {
    style: 'currency',
    currency: currency,
    numberingSystem: digitLength,
  }).format(amount)
};

console.log(CurrencyFormat(56.123456, 'eur', 'fullwide'));
console.log(CurrencyFormat(56.123456));
Mo.
  • 26,306
  • 36
  • 159
  • 225

2 Answers2

2

Add a maximumFractionDigits property to the options with the number of fractional digits you want to permit.

const CurrencyFormat = (amount = 0, currency = 'eur', digitLength = 'latn') => {
  return new Intl.NumberFormat('en-GB', {
    style: 'currency',
    currency: currency,
    numberingSystem: digitLength,
    maximumFractionDigits: 20,
  }).format(amount)
};

console.log(CurrencyFormat(56.123456, 'eur', 'fullwide'));
console.log(CurrencyFormat(56.123456));

I found this by finding the word MaximumFractionDigits in the specification and discovering that it's a property on instances which can be set through the options object..

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
1

maximumFractionDigits helped to get decimal

const CurrencyFormat = (amount = 0, currency = 'eur') => {
  return new Intl.NumberFormat('en-GB', {
    style: 'currency',
    currency: currency,
    maximumFractionDigits: amount.toString().length,
  }).format(amount)
};

console.log(CurrencyFormat(56.123456, 'eur', 'fullwide'));
console.log(CurrencyFormat(56.123456));
Mo.
  • 26,306
  • 36
  • 159
  • 225