1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
pub mod volume; type Percent = u8; pub fn round<F, I>(f: F, digits: I) -> f64 where F: Into<f64>, I: Into<i32> + Copy, { (f.into() * 10_f64.powi(digits.into())).round() / 10_f64.powi(digits.into()) } #[cfg(test)] mod tests { #[test] fn round() { assert_eq!(super::round(0.123456789, 3), 0.123); } }