Skip to content

Spurious failure when casting long strings to decimal #10664

Closed

Description

@neilconway

Describe the bug

Casting a string to a decimal type fails if the input has more than ~76 fractional digits. This is suboptimal, because digits beyond the target scale only matter for rounding, and the correct result is easily representable in the target type.

To Reproduce

use arrow_array::{cast::AsArray, types::Decimal128Type, StringArray};
use arrow_cast::{cast_with_options, CastOptions};
use arrow_schema::DataType;
use std::sync::Arc;

fn main() {
    // 0.111... with 80 fractional digits; at scale 4 this is exactly 0.1111
    let input = format!("0.{}", "1".repeat(80));
    let array = Arc::new(StringArray::from(vec![input])) as arrow_array::ArrayRef;
    let options = CastOptions { safe: false, ..Default::default() };
    let result = cast_with_options(&array, &DataType::Decimal128(38, 4), &options);
    println!("{result:?}");
}

Result

Err(CastError("Cannot cast string '0.11111...11111' to value of Decimal128(38, 10) type"))

Expected behavior

This should succeed and print 0.1111, following the rounding behavior we use for shorter inputs.

Additional context

No response

Activity

  1. added
    bug
    on Aug 12, 2026
  2. added theissue type on Aug 12, 2026
  3. neilconway commented on Aug 12, 2026

    @neilconway
    ContributorAuthor

    take

  4. added a commit that references this issue on Aug 18, 2026
    078c0f1
  5. added a commit that references this issue on Aug 19, 2026
    bbfa4fc
  6. added 3 commits that reference this issue on Aug 26, 2026
    4b5f40b
    a151a27
    0ba9431
  7. added 3 commits that reference this issue on Sep 18, 2026
    4e3e877
    956a803
    2b49b14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions