Skip to main content

amount

Function amount 

Source
pub fn amount(v: f64, unit: &str) -> String
Expand description

A figure in its unit, as every surface spells it. A ratio is a signed percentage with one decimal (percent_text); any other unit is a signed whole number followed by the unit. Neither carries a sign when it rounds to zero, and a value that is not a number prints n/a, so no surface ever shows -0.0% or a figure nobody computed.

Every ratio the calculator derives from a pair is a reduction, 1 - treatment / control: positive means Majordomus used less, and a negative reduction means Majordomus used more. The spelling keeps that sign and never flips it.

use majordomus_cli::economics::report::amount;
assert_eq!(amount(0.2, "ratio"), "+20.0%");
assert_eq!(amount(-0.1, "ratio"), "-10.0%", "a negative reduction stays negative");
assert_eq!(amount(-0.0004, "ratio"), "0.0%", "never -0.0%");
assert_eq!(amount(-1500.4, "tokens"), "-1500 tokens");
assert_eq!(amount(0.3, "tokens"), "0 tokens");
assert_eq!(amount(f64::NAN, "ratio"), "n/a");