akubera / bigdecimal-rs

Arbitrary precision decimal crate for Rust
Other
284 stars 71 forks source link

Panic on round call #90

Closed mashedcode closed 1 year ago

mashedcode commented 2 years ago
use bigdecimal::BigDecimal;
use std::str::FromStr;

fn main() {
    let decimal = BigDecimal::from_str("0.1165085714285714285714285714285714285714").unwrap();
    decimal.round(0); // called `Option::unwrap()` on a `None` value bigdecimal-rs/src/lib.rs:594:43
}

This panics. Complied against master.

Niedzwiedzw commented 2 years ago

same

yamelsenih commented 1 year ago

I think that a simple solution can be trunc the number if the digits is to long that i128 support

Best regards.

yamelsenih commented 1 year ago

Other solution is handle it as String instead

akubera commented 1 year ago

This has been fixed, and the example (for multiple rounding points) has been added to the unit tests.