mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-10 20:29:51 -06:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
cf2fe4733e
commit
97a6a26ca9
@@ -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<u8> {
|
||||
let mut z = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated);
|
||||
|
||||
Reference in New Issue
Block a user