type NumberType = number | string | bigint

Supported input types for number formatting

type RoundingMode = 'half' | 'up' | 'down' | 'banker' | 'truncate'

Strategies for rounding numbers

  • half: Round to the nearest neighbor. If equidistant, round away from zero.
  • up: Round towards Positive Infinity.
  • down: Round towards Negative Infinity.
  • truncate: Round towards Zero.
  • banker: Round to the nearest even neighbor (Statistical rounding).
type NotationMode = 'subscript' | 'scientific'

Modes for special numerical notation

type SignType = '-' | ''

Possible sign values for internal number representation

type RoundingConfigType = Partial<{ rounding: RoundingMode; precision: number; }>

Configuration for rounding operations

  • rounding: The rounding strategy to use
  • precision: Number of decimal places to keep
type NumberConfigType = Partial<{ prefix: string; suffix: string; notation: NotationMode; }>

Configuration for basic number display properties

  • prefix: Text to prepend to the number (e.g., '$')
  • suffix: Text to append to the number (e.g., ' units')
  • notation: The notation style to apply
type ObjectNumberType = { sign: SignType; value: string } & NumberConfigType & Partial<{ compactedSymbol: string; }>

Internal object structure containing full formatting state

  • compactedSymbol: The symbol used for compact notation (e.g., 'K', 'M')
type FormattingConfigType = RoundingConfigType & NumberConfigType & Partial<{ isCompact: boolean; }>

Full configuration options for the formatNumber function

  • isCompact: Whether to use compact notation (K, M, B, etc.)

type FNType = {

round(options?: RoundingConfigType): FNType;

compact(options?: RoundingConfigType): FNType;

notation(mode?: NotationMode): FNType;

prefix(symbol: string): FNType;

suffix(symbol: string): FNType;

toNumber(): string;

toObject(): ObjectNumberType;

};

Fluent API interface for chainable number formatting operations.

  • round: Rounds the number based on the provided precision and strategy.
  • compact: Converts the number to a compact representation (e.g., 1K, 1M, 1B).:
  • notation: Sets the notation style for the number (e.g., scientific, subscript).:
  • prefix: Adds a prefix to the formatted number string.:
  • suffix: Adds a suffix to the formatted number string.:
  • toNumber: Finalizes the chain and returns the formatted number as a string.:
  • toObject: Returns the internal state of the number as an ObjectNumberType.:
type ParseNumberParamsType = Partial<{ fallback: string; }>

Configuration for input parsing

  • fallback: Value to return if parsing fails. Default is '--'

COPYRIGHT © 2026