From 1090ca2d70400fa13bb6949243dd755478416dc7 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Mon, 19 Oct 2026 13:55:10 +0000 Subject: [PATCH] Apply trailing-comma thousands scaling to formats with decimals Found while testing crates/model/src/numfmt.rs:256 (fixed) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/model/src/numfmt.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/model/src/numfmt.rs b/crates/model/src/numfmt.rs index c3cf1713..a43ab719 100644 --- a/crates/model/src/numfmt.rs +++ b/crates/model/src/numfmt.rs @@ -253,7 +253,7 @@ fn fixed(toks: &[Tok], first: usize, last: usize, v: f64, sep: char, dec: char) let grouping = int_part.iter().any(|t| *t == Tok::Comma || matches!(t, Tok::Lit(s) if s.trim().is_empty())); // Commas right after the last digit scale by a thousand each (`#,##0,` = thousands). let after = toks.get(last + 1..).unwrap_or(&[]); - let scale_commas = if dot.is_none() { after.iter().take_while(|t| **t == Tok::Comma).count() } else { 0 }; + let scale_commas = after.iter().take_while(|t| **t == Tok::Comma).count(); let min_int = int_part.iter().filter(|t| **t == Tok::Digit('0')).count(); let frac_digits: Vec = frac_part.iter().filter_map(|t| if let Tok::Digit(c) = t { Some(*c) } else { None }).collect(); let max_frac = frac_digits.len(); @@ -314,6 +314,12 @@ mod tests { assert_eq!(format("\"x\"0", 5.0, None), "x5"); } + #[test] + fn trailing_commas_with_decimals() { + assert_eq!(format("0.0,,", 15_000_000.0, Some("en-US")), "15.0"); + assert_eq!(format("0.00,\"K\"", 15_000.0, Some("en-US")), "15.00K"); + } + #[test] fn scientific_formats() { assert_eq!(format("0.00E+00", 1234.0, None), "1.23E+03");