aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: c41b79163b6c4c63d3e7a429306232500a7633e4 (plain) (blame)
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);
    }
}