Crate round_to

Source
Expand description

Round floating point to integer.

§Usage

You can round to i32 and i64 explicitly:

use round_to::*;

assert_eq!(0.4.round_to_i32(), 0);
assert_eq!(0.6.round_to_i64(), 1);

or implicitly to i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize:

use round_to::*;

let a: i8 = 0.4.round_to();
assert_eq!(a, 0);

using these modes:

use round_to::*;

assert_eq!(0.5.round_to_i32(), 0);
assert_eq!(0.5.floor_to_i32(), 0);
assert_eq!(0.5.ceil_to_i32(), 1);

Traits§

CeilTo
Ceil floating point to integer.
CeilToI32
Ceil floating point to integer.
CeilToI64
Ceil floating point to integer.
FloorTo
Floor floating point to integer.
FloorToI32
Floor floating point to integer.
FloorToI64
Floor floating point to integer.
RoundTo
Round floating point to integer.
RoundToI32
Round floating point to integer.
RoundToI64
Round floating point to integer.