Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
Intl NumberFormat currency per unit

I need to format prices per unit. i.e. 2 336 €/m², $2.336/ac.

Intl.NumberFormat works with currency OR unit style. Can't use both.

How shall one format currency per unit?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have THREE issues

  1. Intl numberformat for currency
  2. Intl numberformat for units
  3. Using units that are not supported: Exponent notation for Intl.NumberFormat

const sups = ["²", "³"];
const currencyPerUnit = (amount, unit, sup, noDec, locale = "en-US", currency = "USD", ) => {
  const numberWithCurrency = (amount).toLocaleString(locale, {
    style: 'currency',
    currency: currency,
    minimumFractionDigits: noDec ? 0 : 2,
  });
  const units = (amount).toLocaleString('fr-FR', {
    style: 'unit',
    unit: unit,
    unitDisplay: 'short'
  }).split(/\s+/).pop();
  return `${numberWithCurrency}/${units}${sup ? sups[sup-2] : ""}`;
};

console.log(currencyPerUnit(1234, "meter", 2, true, "fr-FR", "EUR")); // Euro per m² in French
console.log(currencyPerUnit(1234.14, "acre", 0, false)); // USD per acre
console.log(currencyPerUnit(1234.14, "acre", 2, true, "fr-FR", "EUR")); // Eure per square acre in French

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda