diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-01-20 17:49:23 -0330 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-01-20 17:49:23 -0330 |
| commit | 5405811eaa2af3e84cc3423010488d8429657bb8 (patch) | |
| tree | d74df7e2c498e0db5b2b045444656026e14488a8 /src/lib.rs | |
| parent | 4efbba96bbdf3dddeb0a853310b08a5281d2f8a0 (diff) | |
| download | volute-5405811eaa2af3e84cc3423010488d8429657bb8.zip | |
round displacement when converting units
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); + } +} |