Closed zzhengzhuo closed 1 year ago
This appears to be related to the rounding that is happening during to_f64
:
let round_to = 10f64.powi(self.scale() as i32);
Some((value * round_to).round() / round_to)
In this case, we try doing the following:
100000000000000000000000 / 1000000000000000000
This fails in the last case due to an approximation issue. Interestingly enough this doesn't need to be rounded since we're already dealing with an integer due to a zero fractal component so we can just return early. I'll whip together a PR demonstrating this.
When
100000.000000000000000000
converting to f64, it will lose accuracy. But for10000.000000000000000000
and1000000.000000000000000000
, it works well.The test code is
The result is
The rust-decimal version is
1.32.0