Basic module

formatInt

procedure · 1 overloadSource

Wraps an integer for print so it comes out in another base, padded, or grouped.

formatInt :: (
    value: Any,
    base := 10,
    minimum_digits := 1,
    padding: u8 = #char "0",
    digits_per_comma: u16 = 0,
    comma_string := ""
) -> FormatInt

Parameters

value: Any
base := 10
from 2 to 64. Digits past 9 are a to z, then A to Z.
minimum_digits := 1
pads the digits with padding up to this many. A minus sign is not counted.
padding: u8
the byte used to pad, 0 by default.
digits_per_comma: u16
puts comma_string between groups of this many digits, counted from the right. 0 for no groups.
comma_string := ""
what goes between the groups, for example ",".

Returns

FormatInt
ExampleOpen in playground ↗
assert(tprint("%", formatInt(255, base = 16)) == "ff");
assert(tprint("%", formatInt(7, minimum_digits = 3)) == "007");
assert(tprint("%", formatInt(1234567, digits_per_comma = 3, comma_string = ",")) == "1,234,567");

See also