billios 0.2.0

A soil library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Traits
//!
use crate::math::utilities::GetNumPower;

/// A trait for adding the ability to round to (n) decimal places.
pub trait Rounding {
  /// Round a floating point number to the number (n) decimal points.
  fn round_n(&self, number: f64, n: u32) -> Result<f64, ()> {
    let power: f64 = GetNumPower::power_10(n).into();

    let result = (number * power).round() / power;

    Ok(result)
  }
}