fix(shipping): prevent float truncation in create_quote_from_float and zero-pad cents in Display - #3878
Merged
julianocosta89 merged 2 commits intoSep 2, 2026
Conversation
…d zero-pad cents in Display
Use round() on the scaled total cents before integer division and modulo to avoid IEEE-754 float truncation (e.g. 8.99 * 100.0 yielding 98 cents instead of 99 cents). Also update fmt::Display for Quote to format cents with 2-digit zero-padding ({:02}), preventing single-digit currency strings in span attributes and events.
Fixes open-telemetry#3877
Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes shipping quote precision and formatting issues described in #3877.
Changes:
- Rounds total cents before integer conversion.
- Zero-pads displayed cents and expands regression tests.
- Documents the fix in the changelog.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/shipping/src/shipping_service/quote.rs |
Corrects conversion, formatting, and tests. |
CHANGELOG.md |
Records the shipping fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
julianocosta89
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes #3877
Problem & Root Cause
src/shipping/src/shipping_service/quote.rs,create_quote_from_floatconvertsf64using((value * 100_f64) as u32) % 100. Due to IEEE-754 binary floating-point representation, multiplying common monetary values such as8.99 * 100.0produces898.9999999999999. Directly castingas u32truncates towards zero to898, settingcents: 98($8.98) instead ofcents: 99($8.99). This caused shipping quotes to drop 1 cent on quantities like 1 item ($8.99 -> $8.98), 4 items ($35.96 -> $35.95), and 8 items ($71.92 -> $71.91).fmt::Display for Quoteformatted quotes usingwrite!(f, "{}.{}", self.dollars, self.cents), outputting single-digit cents without zero-padding whencents < 10(e.g."0.1"for 1 cent and"10.5"for 5 cents), corruptingdemo.shipping.cost.totaltelemetry attributes and span events.Solution
(value * 100_f64).round() as u64before integer division and modulo increate_quote_from_float.fmt::Display for Quoteto format cents with 2-digit zero padding ({}.{:02}).src/shipping/src/shipping_service/quote.rsto verify accurate conversion and display across edge cases (8.99,19.99,35.96,71.92,0.01,10.05,100.00).Merge Requirements
CHANGELOG.mdupdated to document the fix