Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda