# format
Printf-style string formatting. Interpolates arguments into a format string
using `%`-prefixed conversion specifiers (C `printf` / Go `fmt` convention).
## Syntax
[format $fmt $args...]
## Parameters
- `$fmt` — Format string containing literal text and `%` conversion specifiers.
- `$args...` — Values to interpolate, one per specifier (in order).
## Conversions
| Spec | Output |
|---|---|
| `%d`, `%i` | Signed integer |
| `%u` | Unsigned integer |
| `%x`, `%X` | Hex (lower/upper) |
| `%o` | Octal |
| `%b` | Binary |
| `%c` | Character (from codepoint or first char of string) |
| `%s` | String (value coerced via `str`) |
| `%q` | Double-quoted string with escapes |
| `%t` | Boolean (`true` / `false`) |
| `%v` | Default value rendering (keywords keep their `:`) |
| `%f`, `%F` | Fixed-point (upper variant → `INF`/`NAN`) |
| `%e`, `%E` | Scientific (`d.dddddde±dd`) |
| `%g`, `%G` | General — shortest of `%e`/`%f` (trailing zeros trimmed) |
| `%%` | Literal `%` |
## Flags, width, precision
A full spec is `%[flags][width][.precision]conv`:
| Flag | Effect |
|---|---|
| `-` | Left-justify within width |
| `+` | Force sign for positive numbers |
| ` ` (space) | Space before positive numbers |
| `0` | Pad with zeros (after sign / base prefix) |
| `#` | Alternate form (`0x`/`0b`/`0` prefix for ints) |
- `width` — Minimum field width; space-padded by default.
- `.precision` — For integers: minimum digits. For floats (`%f`/`%e`): digits
after the point (default 6). For `%g`: significant digits (default 6). For
`%s`: maximum characters.
C length modifiers (`h`, `l`, `ll`, `z`, `j`) are accepted and ignored — Deft
numbers are all `f64`. (`%t` is reserved for booleans.)
## Examples
[format "%d times %#x is %e" 10 10 100] # "10 times 0xa is 1.000000e+02" [format "%s=%d" "x" 5] # "x=5" [format "%.2f" 3.14159] # "3.14" [format "%05d" 42] # "00042" [format "%-8s|" "hi"] # "hi |" [format "%+08.2f" 3.14] # "+0003.14" [format "%#06X" 255] # "0X00FF" [format "%g" 0.0001] # "0.0001" [format "%g" 0.00001] # "1e-05" [format "100%%"] # "100%" [format "%c" 65] # "A" [format "%q" "a\"b"] # "\"a\\\"b\""
## Notes
- Scientific exponents always carry a sign and use at least two digits
(`1.5e+00`), matching the C convention.
- Non-numeric arguments used with integer/float conversions are treated as `0`.
- For simple interpolation, prefer the `"hello $name"` string-interpolation
syntax; reach for `format` when you need width, precision, or non-decimal
conversions.
## Returns
Formatted string.
## See Also
`str`, `join`, `upper`, `lower`, `pad-left`, `pad-right`