Merge 'Fix floating point truncation in JSON #877' from lgualtieri75

Fixes #877

Closes #967
This commit is contained in:
Pekka Enberg
2025-02-10 17:38:59 +02:00
4 changed files with 10 additions and 9 deletions

5
Cargo.lock generated
View File

@@ -1645,6 +1645,7 @@ dependencies = [
"rstest",
"rusqlite",
"rustix",
"ryu",
"serde",
"sqlite3-parser",
"strum",
@@ -2680,9 +2681,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.18"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
[[package]]
name = "same-file"

View File

@@ -72,6 +72,7 @@ strum = "0.26"
parking_lot = "0.12.3"
tracing = "0.1.41"
crossbeam-skiplist = "0.1.3"
ryu = "1.0.19"
[build-dependencies]
chrono = "0.4.38"

View File

@@ -785,13 +785,8 @@ pub trait Formatter {
writer.write_all(infinity.as_bytes())?;
}
_ => {
// let mut buffer = ryu::Buffer::new();
// let s = buffer.format_finite(value);
// This the previous implementation present in the package
// However, serde_json does it differently above.
// Not sure if there if its done like this because of the precision
let s = &format!("{:.1}", value);
let mut buffer = ryu::Buffer::new();
let s = buffer.format_finite(value);
writer.write_all(s.as_bytes())?;
}
}

View File

@@ -637,6 +637,10 @@ do_execsql_test json_object_simple {
SELECT json_object('key', 'value');
} {{{"key":"value"}}}
do_execsql_test json_object_f64 {
SELECT json_object('key', 40.7128);
} {{{"key":40.7128}}}
do_execsql_test json_object_nested {
SELECT json_object('grandparent',json_object('parent', json_object('child', 'value')));
} {{{"grandparent":{"parent":{"child":"value"}}}}}