bigdecimal-rs icon indicating copy to clipboard operation
bigdecimal-rs copied to clipboard

round method works incorrectly for zero decimal places

Open ice1080 opened this issue 4 months ago • 2 comments

The .round(round_digits) method does not work for rounding to zero decimal places.

let unrounded = BigDecimal::from_str("-0.68")?;
println!("{}", unrounded.round(0));
// output is 1 -- incorrect
println!("{}", unrounded.with_scale_round(0, RoundingMode::HalfUp));
// output is -1 -- correct

I do recognize that the docs for round specify that it is used for rounding to round_digits after the decimal point, but it seems confusing that a round method doesn't work for round_digits less than 1.

Return number rounded to round_digits precision after the decimal point

Shouldn't round work the same as with_scale_round just using the default rounding mode?

ice1080 avatar Oct 04 '24 16:10 ice1080