aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index cd3320a..c41b791 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);
+ }
+}