Skip to content

Format Number

Overview

FormatNumber provides locale-aware number formatting powered by the browser’s Intl.NumberFormat API. Supports decimal, currency, percent, and compact notation styles.

Usage

import { formatNumber } from "@paramanu/utilities-js"
formatNumber(1234.56, { style: "currency", currency: "EUR", locale: "de-DE" })
// => "1.234,56 EUR"
formatNumber(1500000, { notation: "compact" })
// => "1.5M"

Guidelines

  • Always specify a currency when using style="currency"
  • Use notation="compact" for large numbers in space-constrained UIs
  • The locale defaults to "en-US" but inherits from LocaleProvider context
  • Renders as a <span> by default; use the as prop to change the element

API

PropTypeDefaultDescription
valuenumber-The number to format
localestring"en-US"BCP 47 language tag
style"decimal" | "currency" | "percent""decimal"Formatting style
currencystring-ISO 4217 currency code
notation"standard" | "compact" | "scientific""standard"Notation style
asElementType"span"HTML element to render