You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this issue when parsing JSON with floats that are sometimes written in scientific notation. When a float exceeds the maximum scale, it is simply cut off by rust_decimal when it's written in decimal notation, but in scientific notation, an error is generated. To reproduce:
#[derive(serde::Deserialize)]
struct F {
f: rust_decimal::Decimal
}
// Simply parsing as a `serde_json::Value` works fine.
assert!(serde_json::from_str::<serde_json::Value>(
r#"{ "f": 1E-29 }"#,
).is_ok());
// Parsing the same number in decimal notation to a `rust_decimal::Decimal` is fine too.
assert!(serde_json::from_str::<F>(
r#"{ "f": 0.00000000000000000000000000001 }"#,
).is_ok());
// But parsing it when written in scientific notation fails.
assert!(serde_json::from_str::<F>(
r#"{ "f": 1E-29 }"#,
).is_err());
The text was updated successfully, but these errors were encountered:
janlugt
changed the title
Handling of maximum scale is inconsistent between decimal and scientific notation
Handling of maximum precision is inconsistent between decimal and scientific notation
Feb 24, 2025
I ran into this issue when parsing JSON with floats that are sometimes written in scientific notation. When a float exceeds the maximum scale, it is simply cut off by
rust_decimal
when it's written in decimal notation, but in scientific notation, an error is generated. To reproduce:The text was updated successfully, but these errors were encountered: