/// Round to N decimal places.
pub fn round(value: f64, decimals: u32) -> f64 {
let factor = 10_f64.powi(decimals as i32);
(value * factor).round() / factor
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_round() {
assert_eq!(round(1.23456, 2), 1.23);
assert_eq!(round(1.235, 2), 1.24);
assert_eq!(round(100.0, 2), 100.0);
}
}