Float

Trait Float 

Source
pub trait Float {
    // Required methods
    fn round_dp(self, decimal_places: u32) -> Self;
    fn ceil_dp(self, decimal_places: u32) -> Self;
    fn floor_dp(self, decimal_places: u32) -> Self;
}

Required Methods§

Source

fn round_dp(self, decimal_places: u32) -> Self

Rounds the number to the given number of decimal places

§Examples
use common_math::rounding::*;

assert_eq!(123.456_f64.round_dp(2), 123.46_f64);
assert_eq!(123.456_f64.round_dp(0), 123_f64);
assert_eq!(123.456_f32.round_dp(2), 123.46_f32);
Source

fn ceil_dp(self, decimal_places: u32) -> Self

Rounds the number up to the given number of decimal places

§Examples
use common_math::rounding::*;

assert_eq!(123.454_f64.ceil_dp(2), 123.46_f64);
assert_eq!(123.456_f64.ceil_dp(0), 124_f64);
assert_eq!(123.454_f32.ceil_dp(2), 123.46_f32);
Source

fn floor_dp(self, decimal_places: u32) -> Self

Rounds the number down to the given number of decimal places

§Examples
use common_math::rounding::*;

assert_eq!(123.456_f64.floor_dp(2), 123.45_f64);
assert_eq!(123.456_f64.floor_dp(0), 123_f64);
assert_eq!(123.454_f32.floor_dp(2), 123.454_f32);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Float for f32

Source§

fn round_dp(self, decimal_places: u32) -> f32

Source§

fn ceil_dp(self, decimal_places: u32) -> f32

Source§

fn floor_dp(self, decimal_places: u32) -> f32

Source§

impl Float for f64

Source§

fn round_dp(self, decimal_places: u32) -> f64

Source§

fn ceil_dp(self, decimal_places: u32) -> f64

Source§

fn floor_dp(self, decimal_places: u32) -> f64

Implementors§