From 97a6a26ca9e384fc1865f2a5352f80a8cd05adb8 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 24 Oct 2026 16:02:47 +0200 Subject: [PATCH] Format negative zero as 0 in spreadsheet import (#4040) Found while testing crates/formats/src/sheet.rs:726-727 (fn number) Co-authored-by: Claude Haiku 5.5 --- crates/formats/src/sheet.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/formats/src/sheet.rs b/crates/formats/src/sheet.rs index 49cc1259fa..520fca2f80 100644 --- a/crates/formats/src/sheet.rs +++ b/crates/formats/src/sheet.rs @@ -724,7 +724,8 @@ fn number(x: f64) -> String { return x.to_string(); } if x.fract() == 0.0 && x.abs() < 1e15 { - return format!("{x:.0}"); + // `+ 0.0` turns negative zero into positive zero, which would print as "-0". + return format!("{:.0}", x + 0.0); } let rounded: f64 = format!("{x:.14e}").parse().unwrap_or(x); if rounded.abs() >= 1e15 || rounded.abs() < 1e-9 { format!("{rounded:E}") } else { rounded.to_string() } @@ -1006,6 +1007,11 @@ mod tests { use super::*; use std::io::Write; + #[test] + fn negative_zero_formats_as_zero() { + assert_eq!(number(-0.0), "0"); + } + fn zip(entries: &[(&str, &str)]) -> Vec { let mut z = zip::ZipWriter::new(Cursor::new(Vec::new())); let o = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated);