# `PhoenixKit.Utils.Format`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.165/lib/phoenix_kit/utils/format.ex#L1)

Workspace-shared formatting helpers for numeric / size values.

# `bytes`

```elixir
@spec bytes(
  integer() | Decimal.t() | nil,
  keyword()
) :: String.t()
```

Formats a byte count as a human-readable size string.

Accepts an integer, `Decimal`, or `nil`. Returns the `:unknown` option
string for `nil` (or any unrecognised input) and rounds to `:decimals`
decimal places for the chosen unit. The unit auto-scales to B / KB /
MB / GB based on the size.

## Options

- `:decimals` — decimal places for KB/MB/GB output. Default `1`.
- `:unknown` — string returned for `nil` or unrecognised inputs.
  Default `"Unknown"`. Pass `"0 B"` to mimic the file-picker shape.
- `:base` — `1024` (binary, default) or `1000` (decimal/SI). Some
  media-browser surfaces use the decimal convention to match what
  operating systems show; everything else defaults to the binary
  convention common in dev tooling.

## Examples

    iex> PhoenixKit.Utils.Format.bytes(0)
    "0 B"

    iex> PhoenixKit.Utils.Format.bytes(1500)
    "1.5 KB"

    iex> PhoenixKit.Utils.Format.bytes(1_500_000, decimals: 2)
    "1.43 MB"

    iex> PhoenixKit.Utils.Format.bytes(1_500_000, base: 1000, decimals: 2)
    "1.5 MB"

    iex> PhoenixKit.Utils.Format.bytes(nil, unknown: "0 B")
    "0 B"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
