math::round

Function half_to_odd

Source
pub fn half_to_odd(value: f64, scale: i8) -> f64
Expand description

Round half to nearest odd number.

Round value to accuracy defined by scale rounding half to nearest odd number. Positive scale defines the number of decimal digits in the result while negative scale rounds to a whole number and defines the number of trailing zeroes in the result.

§Arguments

  • value - value to round
  • scale - result accuracy

§Examples

use math::round;

let rounded = round::half_to_odd(3.14159, 3);
assert_eq!(rounded, 3.141);
use math::round;

let rounded = round::half_to_odd(3456., -2);
assert_eq!(rounded, 3500.);