refactor(import): Decimal arithmetic goes through the kernel (K-U12)
The raw-decimal-arith detector counted 18 places in ledger-import before and counts 0 after. No figure changes. Signs (bank_csv, iif, invoice_pdf, report) go through money::neg and money::signed_amount; sums and differences of figures from the books (report, xlsx) through total_of, add_in_range and sub_in_range, which are exact and panic only where the raw operator panicked. Not a plain sum or sign: equal_shares (templates) now divides through Amount::checked_div, rounds half-to-even to two places through round_places, and gives the last owner a hundred minus the shares given. Same numbers as before for every n >= 1; for n = 0 it returns no shares where the raw division panicked (its one caller passes the owners of a partnership, at least two). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0de906e9ed
commit
0fb19b4b25
6 files changed
+43
-20
No files matched your search
@@ -118,7 +118,7 @@ pub fn parse_bank_csv_with(
|
||||
4 => {
|
||||
// Money out in the third column, money in in the fourth.
|
||||
match (!fields[2].is_empty(), !fields[3].is_empty()) {
|
||||
(true, false) => -parse_amount(fields[2])?,
|
||||
(true, false) => ledger_core::money::neg(parse_amount(fields[2])?),
|
||||
(false, true) => parse_amount(fields[3])?,
|
||||
(false, false) => Decimal::ZERO,
|
||||
(true, true) => {
|
||||
@@ -227,7 +227,7 @@ fn parse_amount(s: &str) -> Result<Decimal, BankCsvError> {
|
||||
return Err(bad());
|
||||
}
|
||||
if neg {
|
||||
amount = -amount;
|
||||
amount = ledger_core::money::neg(amount);
|
||||
}
|
||||
Ok(amount)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user