fix(viewer): percentages are Decimal, never f64
fmt::pct_change divided money amounts in f64 (a money path, AGENTS.md rule 1) and fmt::compact shortened amounts through f64; both are now Decimal via kernel::percent_of and round_display. profit::pct, the reports change and share columns follow the one percent rule: no percent of a zero or negative base (shown as nothing or an em dash). Every pages round_dp call goes through round_display; books' cent truncations keep their toward-zero leftover policy through kernel::round_places. Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
1 parent
a414462be7
commit
a7d0c7f2d3
8 files changed
+166
-54
No files matched your search
@@ -24,9 +24,14 @@ pub fn kind_label(k: CapitalKind) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// A share as a percent: 0.5 → "50%", 0.3333 → "33.33%".
|
||||
/// A share as a percent: 0.5 → "50%", 0.3333 → "33.33%". A share is a
|
||||
/// stored fraction, not a ratio of two amounts, so this is exact
|
||||
/// decimal multiplication (never a float, never rounded); only a
|
||||
/// negative zero is dropped.
|
||||
pub fn percent(share: Decimal) -> String {
|
||||
format!("{}%", (share * Decimal::ONE_HUNDRED).normalize())
|
||||
let p = share * Decimal::ONE_HUNDRED;
|
||||
let p = if p.is_zero() { Decimal::ZERO } else { p };
|
||||
format!("{}%", p.normalize())
|
||||
}
|
||||
|
||||
/// One statement row: an indented label, an amount column, and an
|
||||
|
||||
Reference in new issue
Block a user