From 3246587e855e7ba3e533c5b5394d5d5c1f4004ca Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Tue, 20 Oct 2026 17:38:34 +0000 Subject: [PATCH] Return empty WordNum result when cents rounding carries to 1e12 Found while testing crates/js/src/formcalc.rs:2024-2050 (word_num) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/js/src/formcalc.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/js/src/formcalc.rs b/crates/js/src/formcalc.rs index dc32d457b..e39992390 100644 --- a/crates/js/src/formcalc.rs +++ b/crates/js/src/formcalc.rs @@ -2027,6 +2027,10 @@ fn word_num(n: f64, cents: bool) -> String { } let cents_total = (n * 100.0).round() as u64; let whole = if cents { cents_total / 100 } else { n.trunc() as u64 }; + if whole >= 1_000_000_000_000 { + // Rounding to cents carried past the supported range. + return String::new(); + } let mut parts = Vec::new(); let groups = [(1_000_000_000u64, "Billion"), (1_000_000, "Million"), (1_000, "Thousand")]; let mut rest = whole; @@ -2596,6 +2600,7 @@ mod tests { assert_eq!(parse_date("2/3/01", "M/D/YY"), Some((2001, 2, 3))); assert_eq!(format_date(2001, 2, 3, "MMMM D, YYYY"), "February 3, 2001"); assert_eq!(word_num(1234.5, true), "One Thousand Two Hundred Thirty-Four Dollars And 50 Cents"); + assert_eq!(word_num(999_999_999_999.999, true), ""); assert_eq!(num_text(3.0), "3"); assert_eq!(num_text(2.5), "2.5"); assert_eq!(num_text(0.1 + 0.2), "0.3");