Skip to content

Conversation

@hugobast
Copy link
Contributor

@hugobast hugobast commented Nov 5, 2025

Providing a fix for #760 in case there's appetite for it.

In my opinion this is a bug worth fixing because it aligns with this crate's purpose, it was surprising to discover that "1.0" would get turned into "1".

It's an unfortunate side effect of serde_json's arbitrary_precision logic which for some values (0.0, 1.0, ...) will decide to use visit_f64 instead of a visit_map.

Key Changes

  • Added ryu dependency to Cargo.toml (only for serde-with-arbitrary-precision)
  • Implemented feature-gated visit_f64 method using ryu::Buffer::format_finite() for float representation
  • Added test case verifying that 1.0 maintains its precision during serialization/deserialization

Rationale

The decision to include ryu as a dependency with the feature serde-with-arbitrary-precision aligns with serde_json's own usage of said dependency with arbitrary_precision enabled.

@Tony-Samuels
Copy link
Collaborator

I didn't realise this was easy to fix. Nice job.

@Tony-Samuels Tony-Samuels merged commit db61f68 into paupino:v1 Nov 5, 2025
15 checks passed
@Tony-Samuels
Copy link
Collaborator

Please can you raise a similar MR against master? If you'd rather, I'm also happy to do so.

@hugobast
Copy link
Contributor Author

Please can you raise a similar MR against master? If you'd rather, I'm also happy to do so.

Sorry I didn't catch that, I'm working on an update and I'll make sure that I raise it against master too.

hugobast added a commit to hugobast/rust-decimal that referenced this pull request Jan 14, 2026
This change moves from ryu to zmij for floating-point to string
conversion in serde arbitrary precision deserialization.

This follows the same direction as serde_json:
serde-rs/json#1304

Related to: paupino#761
hugobast added a commit to hugobast/rust-decimal that referenced this pull request Jan 14, 2026
Uses zmij for floating-point to string conversion to avoid precision
loss during deserialization.

This follows the same direction as serde_json:
serde-rs/json#1304

Related to: paupino#761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants