pub fn label_currency(
prefix: &str,
suffix: &str,
big_mark: &str,
accuracy: Option<f64>,
) -> impl Fn(f64) -> String + Send + SyncExpand description
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 ..
use ggplot_rs::scale::format::label_currency;
let eur = label_currency("€", "", ".", Some(1.0));
assert_eq!(eur(-1234567.0), "-€1.234.567");
let chf = label_currency("", " CHF", "'", Some(0.01));
assert_eq!(chf(9876.5), "9'876.50 CHF");