diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -1,3 +1,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); + } +} |