merge: one rounding for display, percentages in Decimal (K-U9; checked, one fix)
Three crates each rounded an amount for display in their own way, and
the viewer computed its percentages in f64. Money is never a float, not
for a ratio either (AGENTS.md's first rule), and a figure shown should
not depend on which renderer drew it.
- `ledger_import::format::round_display(amount, places)`: half away
from zero through the kernel's `round_places`, never a negative zero.
The reports' text, the PDFs, the spreadsheet, the CPA package's text
and the viewer's formatting all call it.
- The viewer's percentages (`fmt::pct_change`, the Profit page, the
reports' change and share-of-income columns) are the kernel's
`percent_of` on Decimals.
What a reader sees differently, by principle and not by accident:
- `compact` rounds half away from zero like every other figure:
1,250,000 reads $1.3M (was $1.2M), 10,500 reads $11k (was $10k).
- A change against a base that is zero or negative shows no percentage
("—"), where it used to show one with a misleading sign: from a loss
of 100 to a loss of 50 is not "50% down".
No booked figure moves and no golden changed. One fix on merge: the
demo books' platform fee is a booked amount, so it uses the kernel's
rounding with the rule it always had (a half to the even cent), not the
display rounding the branch had put there; the demo books are unchanged.
Shown on main: clippy clean on the three crates; ledger-import's unit
tests 44 passed and spec_import, labels, templates 91 passed;
ledger-package 49 passed; the viewer's unit tests 62 passed, and
display_rounding, view_model, sidenav, spec_gui, odd_cent 59 passed;
ledger-core's bookspec checks 78 passed (the worker's one failure there
was its old base, which lacked the pin at bookspec 79cb439).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
0e9990f111
17 files changed
+506
-62
No files matched your search
@@ -788,7 +788,16 @@ pub fn build(dir: &Path, today: NaiveDate) -> Result<(), StoreError> {
|
||||
let date = day(m, 1);
|
||||
if in_range(date) {
|
||||
let gross = rng.amount(450, 1600);
|
||||
let fee = (gross * Decimal::new(10, 2)).round_dp(2) + Decimal::new(30, 2);
|
||||
// A booked figure, so the kernel's rounding and not the
|
||||
// display's: ten percent to the cent, a half to the even
|
||||
// cent, as these books have always been drawn.
|
||||
let fee = ledger_core::kernel::round_places(
|
||||
gross * Decimal::new(10, 2),
|
||||
2,
|
||||
ledger_core::kernel::Rounding::HalfToEven,
|
||||
)
|
||||
.expect("a tenth of a four-digit sale rounds to the cent")
|
||||
+ Decimal::new(30, 2);
|
||||
let net = gross - fee;
|
||||
let e = s.create_entry(date, "Gumroad payout — template sales")?;
|
||||
s.add_line(e, checking, Side::Debit, usd(net))?;
|
||||
|
||||
Reference in new issue
Block a user