Skip to main content

round_f64

Function round_f64 

Source
pub fn round_f64(value: f64, decimals: u32) -> f64
Expand description

Round a floating point value to decimals decimal places.

ยงExamples

use tokmd_math::round_f64;

assert_eq!(round_f64(12.34567, 2), 12.35);
assert_eq!(round_f64(12.34567, 4), 12.3457);
assert_eq!(round_f64(1.5, 0), 2.0);

Rounding at zero decimal places:

use tokmd_math::round_f64;

assert_eq!(round_f64(2.4, 0), 2.0);
assert_eq!(round_f64(2.6, 0), 3.0);