Parsing decimals truncates extra digits, but casting them rounds extra digits
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 167
Description
**Describe the bug**
Best I can tell from the code:
* parsing the string `"1.99"` as a scale-1 decimal produces `1.9`
* casting the scale-2 decimal `1.99` to scale-1 produces `2.0`
**To Reproduce**
```rust
// 1.99 -> 1.9 at scale 1, stored as 19
assert_eq!(parse_decimal::("1.99", 10, 1), Ok(19));
```
vs
```rust
let input = Decimal128Array::from(vec![Some(199i128)])
.with_precision_and_scale(10, 2)
.unwrap();
let out = cast(&input, &DataType::Decimal128(10, 1)).unwrap();
// 1.99 → 2.0 at scale=1, stored as 20
assert_eq!(out.as_primitive::().value(0), 20i128);
```
**Expected behavior**
It seems like the two operations should have the same behavior, likely `2.0`?
**Additional context**
Rabbit-hole off of https://github.com/apache/arrow-rs/pull/8700#issuecomment-3897948966
Contributor guide
Assessment
This issue has not been assessed yet.