PhoenixKit.Utils.Number (phoenix_kit v1.5.1)
View SourceNumber formatting utilities for PhoenixKit.
Provides functions for formatting numbers with thousand separators, abbreviations, and other common number formatting needs.
Summary
Functions
Formats a number with thousand separators.
Formats a number as a percentage.
Formats a number with abbreviations (K, M, B).
Functions
Formats a number with thousand separators.
Examples
iex> PhoenixKit.Utils.Number.format(1234567)
"1,234,567"
iex> PhoenixKit.Utils.Number.format(0)
"0"
iex> PhoenixKit.Utils.Number.format(nil)
"0"
Formats a number as a percentage.
Examples
iex> PhoenixKit.Utils.Number.format_percentage(95.5)
"95.5%"
iex> PhoenixKit.Utils.Number.format_percentage(100)
"100%"
iex> PhoenixKit.Utils.Number.format_percentage(nil)
"0%"
Formats a number with abbreviations (K, M, B).
Examples
iex> PhoenixKit.Utils.Number.format_short(1_234_567)
"1.2M"
iex> PhoenixKit.Utils.Number.format_short(5_432)
"5.4K"
iex> PhoenixKit.Utils.Number.format_short(123)
"123"