rust-decimal icon indicating copy to clipboard operation
rust-decimal copied to clipboard

If `f64::try_from(value: Decimal)` is infallible, can we get method on `Decimal` that returns the unwrapped value?

Open hirenhpatel opened this issue 11 months ago • 1 comments

I manually inspected the implementation of converting Decimal to f64 and found that it can never return None. Do I have this right?

If so, would you be able to provide an infallible method directly on Decimal to make this conversion? Right now I have a bunch of f64::try_from(value).expect("infallible by manual inspection") which makes it very difficult to maintain a no-panic codebase.

thanks!

hirenhpatel avatar Jan 25 '25 10:01 hirenhpatel

Previous implementations were returning None under edge cases that have since been handled. I'm not seeing any reason would couldn't have From<f64> implementations now.

Tony-Samuels avatar Jan 26 '25 15:01 Tony-Samuels