refactor(display): one rounding for presentation
Move format_amount's rounding half (half away from zero, never a negative zero) into ledger-import::format::round_display, through the kernel's round_places. format_amount, amount_parts, the PDF percent column, xlsx's exact_f64 and ledger-package's text padding all call it, so a display change never changes a booked figure. Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
1 parent
4da1c5b30f
commit
a414462be7
6 files changed
+81
-5
No files matched your search
@@ -22,7 +22,10 @@ use rust_decimal::Decimal;
|
||||
/// "318.42", "1000.00". Padding only, never rounding: an exact amount with
|
||||
/// more places (an FX-converted line) keeps them. Never "-0".
|
||||
pub fn money(n: Decimal) -> String {
|
||||
let mut n = if n.is_zero() { Decimal::ZERO } else { n };
|
||||
// Padding only, never rounding: the display rounding at the
|
||||
// amount's own scale (at least two places) is the identity, and it
|
||||
// is what drops a negative zero.
|
||||
let mut n = ledger_import::round_display(n, n.scale().max(2));
|
||||
if n.scale() < 2 {
|
||||
n.rescale(2);
|
||||
}
|
||||
@@ -42,6 +45,7 @@ pub fn total_text(total: Option<Decimal>) -> String {
|
||||
/// share, never on its spelling.
|
||||
pub fn share_text(n: Decimal) -> String {
|
||||
let mut n = n.normalize();
|
||||
n = ledger_import::round_display(n, n.scale().max(2));
|
||||
if n.scale() < 2 {
|
||||
n.rescale(2);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user