JSFiddle - React, Tailwind, and code Playground

by BrankoSabo

JavaScript

const a = new Intl.NumberFormat('fr-CA',{style:'currency', currency:'SEK', currencyDisplay: 'code', notation:'compact',maximumFractionDigits: 2}).format(1005)
console.log(a)

function formatCompactMSEK(number) {
  const formatter = new Intl.NumberFormat('fr-CA', {
    style: 'currency',
    currency: 'SEK',
    currencyDisplay: 'code',
    notation: 'compact',
    compactDisplay: 'short',
    maximumFractionDigits: 2
  });

  let formatted = formatter.format(number);

  // Replace the default compact suffix with "MSEK"
  // Note: This approach depends on the locale's compact suffix for millions
  // For 'fr-CA', the short compact for million is likely "M".
  formatted = formatted.replace(/M\s*SEK/, 'MSEK');

  return formatted;
}

// Example Usage
const b = formatCompactMSEK(15000000000);
/* console.log(b); // Outputs: "1,50 MSEK" */