rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
694 stars 131 forks source link

Add `round_to_digit` method to `Float` trait. #317

Open amab8901 opened 5 months ago

amab8901 commented 5 months ago

Add round_to_digit method to Float trait.

Example usage

let full_float = 12.34567;
let rounded_float = full_float.round_to_digit(2);
assert_eq!(rounded_float, 12.35);
cuviper commented 4 months ago

We can only add this if there's a generic implementation. Have you attempted that?

amab8901 commented 4 months ago

yes, I created a crate for this: https://crates.io/crates/round_float

The code is here: https://github.com/amab8901/round_float/blob/master/src/round_float.rs