1 2 3 4 5 6 7 8 9 10 11 12 13 14
/// Computes `number` rounded to `precision`. /// /// # Examples /// /// ```rust /// use lorust::round; /// /// let rounded = round(4.006, 2); /// assert_eq!(rounded, 4.01); /// ``` pub fn round(number: f64, precision: i32) -> f64 { let factor = 10.0_f64.powi(precision); (number * factor).round() / factor }