| Crates.io | round_to_int |
| lib.rs | round_to_int |
| version | 0.1.3 |
| created_at | 2023-10-07 00:00:37.981102+00 |
| updated_at | 2023-10-07 17:16:46.341733+00 |
| description | Round floating point to integer. |
| homepage | |
| repository | https://github.com/lubomirkurcak/round_to_int/ |
| max_upload_size | |
| id | 995762 |
| size | 30,638 |
Round floating point to integer.
You can round to i32 and i64 explicitly:
use round_to_int::*;
assert_eq!(0.4.round_to_i32(), 0);
assert_eq!(0.5.round_to_i64(), 1);
or implicitly to i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize:
use round_to_int::*;
let a: i8 = 0.4.round_to();
assert_eq!(a, 0);
using these modes:
use round_to_int::*;
assert_eq!(0.5.round_to_i32(), 1);
assert_eq!(0.5.floor_to_i32(), 0);
assert_eq!(0.5.ceil_to_i32(), 1);
As of now, everything is implemented using round, floor, and ceil.
When round_ties_even is resolved, this crate will elect to use it instead.
In the future, optimized implementations may be added.