Skip to content

Conversation

@gruuya
Copy link
Contributor

@gruuya gruuya commented Oct 23, 2025

Which issue does this PR close?

Alternative to #8702 (see #8699 for a discussion).

Rationale for this change

Make parsing of zero-scale decimals more correct/consistent.

What changes are included in this PR?

When a decimal with scale 0 is being parsed, but it has some digits pass the decimal point those will effectively be discarded.

Are these changes tested?

Yes.

Are there any user-facing changes?

Aligned parsing of zero-scale decimals.

if scale == 0 && fractionals > 0 {
// The input string contained some fractional digits after the decimal point despite
// the scale being zero. Eject all the fractional digits from the number.
result = result.div_wrapping(base.pow_wrapping(fractionals as _));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be correct if there are many fractional digits, e.g. 20+ ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would, added another test case on that note (("123.000000000000000000004", 123)).

gruuya and others added 2 commits October 24, 2025 14:07
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
@gruuya gruuya force-pushed the fix-zero-scale-decimal-parse branch from 95a0e5a to 124441b Compare October 24, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of parse_decimal with zero scale

2 participants