diff --git a/crates/functions/src/text.rs b/crates/functions/src/text.rs index 8b344d0e6..82ffcf1f5 100644 --- a/crates/functions/src/text.rs +++ b/crates/functions/src/text.rs @@ -373,10 +373,10 @@ fn numbervalue(a: &[Arg], c: &mut dyn Ctx) -> R { /// Formats `x` (already rounded) with `decimals` places and optional thousands separators. fn format_fixed(x: f64, decimals: i64, commas: bool) -> String { let d = decimals.max(0) as usize; - let s = format!("{:.*}", d, x.abs()); + let s = x.abs().to_string(); let (int_part, frac) = match s.split_once('.') { - Some((i, f)) => (i.to_string(), Some(f.to_string())), - None => (s.clone(), None), + Some((i, f)) => (i, f), + None => (s.as_str(), ""), }; let int_part = if commas { let b = int_part.as_bytes(); @@ -389,12 +389,14 @@ fn format_fixed(x: f64, decimals: i64, commas: bool) -> String { } o } else { - int_part + int_part.to_string() }; let mut out = int_part; - if let Some(f) = frac { + if d > 0 { + let frac_len = frac.len().min(d); out.push('.'); - out.push_str(&f); + out.push_str(&frac[..frac_len]); + out.extend(std::iter::repeat_n('0', d - frac_len)); } out } @@ -1281,6 +1283,18 @@ mod tests { is_text(ev("DOLLAR", vec![n(0.5), n(0.0)]), "$1"); is_text(ev("USDOLLAR", vec![n(1.0)]), "$1.00"); is_text(ev("USDOLLAR", vec![n(-1234.567), n(1.0)]), "($1,234.6)"); + let fixed_16 = format!("1.1{}", "0".repeat(15)); + let dollar_16 = format!("$1.1{}", "0".repeat(15)); + let fixed_20 = format!("1.005{}", "0".repeat(17)); + let dollar_20 = format!("$1.005{}", "0".repeat(17)); + let fixed_127 = format!("1.1{}", "0".repeat(126)); + let dollar_127 = format!("$1.1{}", "0".repeat(126)); + is_text(ev("FIXED", vec![n(1.1), n(16.0)]), &fixed_16); + is_text(ev("DOLLAR", vec![n(1.1), n(16.0)]), &dollar_16); + is_text(ev("FIXED", vec![n(1.005), n(20.0)]), &fixed_20); + is_text(ev("DOLLAR", vec![n(1.005), n(20.0)]), &dollar_20); + is_text(ev("FIXED", vec![n(1.1), n(127.0)]), &fixed_127); + is_text(ev("DOLLAR", vec![n(1.1), n(127.0)]), &dollar_127); is_text(ev("T", vec![t("x")]), "x"); is_text(ev("T", vec![n(1.0)]), ""); } diff --git a/docs/function-parity.md b/docs/function-parity.md index 7d511c8e6..51309b6f1 100644 --- a/docs/function-parity.md +++ b/docs/function-parity.md @@ -1,6 +1,6 @@ # Function parity: worksheet functions and formulas -> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (UPPER, LOWER and PROPER use single-character Unicode casing to match measured Excel results; locale check: Windows Excel 16.0 build 20527, LCID 1033; earlier: UNICHAR returns `#N/A` for Unicode noncharacters, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (FIXED and DOLLAR preserve the rounded number's shortest decimal digits before padding high requested precision; measured in Windows Excel 16.0 build 20527, LCID 1033; earlier: UPPER, LOWER and PROPER use single-character Unicode casing to match measured Excel results; locale check: Windows Excel 16.0 build 20527, LCID 1033; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Excel's worksheet functions, category by category, against GridCraft's function library. Part of [target-app-parity.md](target-app-parity.md); gaps feed [gaps.md](gaps.md). @@ -129,6 +129,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | 2026-10-31 | minor | BITLSHIFT and BITRSHIFT return `0` for zero operands shifted beyond 53 bits in either direction; nonzero operands retain the `#NUM!` limit, matching Excel | | 2026-10-31 | minor | UNICHAR returns `#N/A` for U+FDD0–U+FDEF and U+FFFE/U+FFFF on every plane; adjacent valid characters and existing invalid-range/surrogate errors remain unchanged, matching Excel | | 2026-10-31 | minor | UPPER, LOWER and PROPER use single-character casing: `UPPER("Straße")` keeps ß, `LOWER("İ")` returns i, and `PROPER("İSTANBUL")` returns Istanbul, matching Windows Excel 16.0 build 20527 in LCID 1033 | +| 2026-10-31 | minor | FIXED and DOLLAR format the rounded number's shortest decimal representation before padding requested fractional zeroes, so 1.1 at 16 places and 1.005 at 20 places do not expose binary noise; measured in Windows Excel 16.0 build 20527, LCID 1033 | | 2026-10-27 | minor | ECMA.CEILING added to the functions that are in our library but not on Microsoft's list (with USDOLLAR), so the counts don't change | | 2026-10-26 | minor | IMSQRT uses Excel's polar route with its cosine reduction, so `IMSQRT("-4")` is `1.22514845490862E-16+2i` as in Excel (exact `2i` before); the rows list the IM* differences still open | | 2026-10-25 | minor | LAMBDA row: a LAMBDA that calls itself more than 140 times, and a formula nested past the depth limit, give `#NUM!` (#1809; nesting gave `#CALC!` before). `=Foo(1)` where the defined name Foo holds `#N/A` gives `#N/A`, not `#NAME?` |