Skip to content

parse_decimal ignores negative scales #10791

Closed

Description

@neilconway

Describe the bug

Arrow allows negative scales for decimal values.

To Reproduce

use arrow_array::types::Decimal128Type;
use arrow_cast::parse::parse_decimal;

// returns 12345 (i.e. 1234500 at scale -2); expected 12 (1200)
parse_decimal::<Decimal128Type>("1234.5", 10, -2);
// returns 150 (15000); expected 2 (200)
parse_decimal::<Decimal128Type>("150", 10, -2);

Expected behavior

No response

Additional context

No response

Activity

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

    @neilconway
    ContributorAuthor

    take

  4. changed the title [-]`parse_decimal ignores negative scales`[/-] [+]`parse_decimal` ignores negative scales[/+] on Aug 21, 2026
  5. Lstarsky0 commented on Aug 23, 2026

    @Lstarsky0
    Contributor

    scale is used in exactly three places in parse_decimal, and all three assume it's >= 0:

    • :981 if fractionals == scale — the stop condition for consuming fractional digits. Never true for a negative scale, so the whole fraction gets consumed.
    • :1021 if fractionals < scale — the only rescaling step. Also never true.
    • :1024, the multiply inside it.

    result is only ever multiplied in this function; there is no division anywhere. A negative scale needs result / 10^-scale and there's no code path for it, so what comes back is the mantissa digits with the decimal point deleted:

    "1234.5", scale -2  ->  12345
    "150",    scale -2  ->  150
    "1200",   scale -2  ->  1200
    "0.05",   scale -2  ->  5
    

    This only reaches callers who use parse_decimal directly — cast_string_to_decimal refuses negative scale up front at cast/decimal.rs:798, which is the other side of #10792.

  6. added a commit that references this issue on Sep 1, 2026
    70219af
  7. added 3 commits that reference this issue on Sep 18, 2026
    f9eb4aa
    8bac2b6
    e9e1631
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