Skip to main content

Module format

Module format 

Source
Expand description

Label formatting functions for scale breaks. Analogous to R’s scales package (comma, percent, dollar, scientific, number, SI, ordinal, bytes).

Functions§

label_bytes
Byte-size formatter. binary = true uses 1024-based KiB/MiB; otherwise 1000-based kB/MB.
label_comma
Format with comma separators for thousands (e.g., 1,234,567).
label_comma_locale
label_comma with the marks of locale (de-DE: 1.234.567).
label_comma_marks
label_comma with explicit marks: label_comma_marks(",", ".")(1234567.5) is "1.234.567,5".
label_currency
Sign-aware currency formatter (R’s scales::label_currency): the minus sign goes before the prefix (“-€5”, not “€-5”), thousands are grouped with big_mark (e.g. ",", ".", " ", "'"; "" disables grouping), and accuracy rounds to a multiple of it (None = up to two decimals, trailing zeros trimmed). The decimal mark is always ..
label_currency_locale
Currency in the conventions of locale — its symbol, placement and marks: de-DE "1.234,50 €", en-US "$1,234.50", en-GB "£1,234.50", fr-FR "1 234,50 €". Use Locale::with_currency for another symbol.
label_currency_marks
label_currency with an explicit decimal mark as well.
label_dollar
Format as US dollar with thousands separators (e.g., 1234 → “$1,234”, -500 → “-$500”). Equivalent to label_currency("$", "", ",", None).
label_number
General configurable number formatter (R’s scales::label_number). Multiplies by scale, rounds to accuracy (None = trim), groups thousands with ,, and wraps in prefix/suffix — with the minus sign placed before the prefix (-€5). For a custom thousands mark use label_currency.
label_number_locale
label_number (scale 1) with the marks of locale.
label_number_marks
label_number with an explicit decimal mark and thousands mark ("" disables grouping).
label_ordinal
Ordinal formatter: 1 → “1st”, 2 → “2nd”, 3 → “3rd”, 11 → “11th”.
label_percent
Format as percentage (e.g., 0.5 → “50%”).
label_percent_locale
label_percent in the conventions of locale: de-DE / fr-FR "12,3 %", en-US / en-GB "12.3%". accuracy as in label_percent_marks.
label_percent_marks
label_percent with explicit marks and percent suffix ("%", " %"). accuracy is in percentage points (Some(0.1) → one decimal); None matches label_percent.
label_scientific
Format in scientific notation (e.g., 12345 → “1.23e4”).
label_si
SI-prefixed number formatter: 1_500 → “1.5k”, 2.3e6 → “2.3M”, 5e-4 → “500µ”.

Type Aliases§

LabelFormatter
A label formatter — any Fn(f64) -> String. The plain label_* functions coerce into this, and the configurable label_number/label_si/… builders return one directly.