Function lib_rapid::math::general::round_to_n_mult
source · pub fn round_to_n_mult<T: Div<Output = T> + Mul<Output = T> + Sub<Output = T> + Add<Output = T> + PartialOrd + From<bool> + Copy>(
x: T,
n: T
) -> T
Expand description
Rounds to the nearest multiple of n
.
Arguments
x: T
- The number which shall be rounded.n: T
- The multiplicant.
Returns
A T
.
Examples
use lib_rapid::math::general::round_to_n_mult;
assert_eq!(round_to_n_mult(14, 5), 15);
assert_eq!(round_to_n_mult(1932, 2), 1932);
// This function rounds up if in doubt.
assert_eq!(round_to_n_mult(1945, 2), 1946);