#integer-division #round #integer

no-std rounded-div

Get rounded result of an integer division

6 releases

0.1.4 Oct 6, 2025
0.1.3 Feb 21, 2025
0.1.2 Apr 18, 2021
0.0.0 Apr 17, 2021

#376 in Math

Download history 79/week @ 2025-10-16 56/week @ 2025-10-23 26/week @ 2025-10-30 24/week @ 2025-11-06 19/week @ 2025-11-13 47/week @ 2025-11-20 84/week @ 2025-11-27 96/week @ 2025-12-04 59/week @ 2025-12-11 4/week @ 2025-12-18 2/week @ 2025-12-25 55/week @ 2026-01-01 42/week @ 2026-01-08 47/week @ 2026-01-15 29/week @ 2026-01-22 89/week @ 2026-01-29

216 downloads per month
Used in 5 crates

MIT license

9KB
77 lines

rounded-div

Test Crates.io Version

Get rounded result of an integer division.

Usage Examples

const fn rounded_div_*

assert_eq!(rounded_div::i32( 59, 4),  15); // 59/4 is equal to 14.75 which is closer to 15
assert_eq!(rounded_div::i32( 58, 4),  15); // 58/4 is equal to 14.5 which is rounded to 15
assert_eq!(rounded_div::i32( 57, 4),  14); // 57/4 is equal to 14.25 which is closer to 14
assert_eq!(rounded_div::i32(-59, 4), -15);
assert_eq!(rounded_div::i32(-58, 4), -15);
assert_eq!(rounded_div::i32(-57, 4), -14);

trait RoundedDiv

use rounded_div::RoundedDiv;
assert_eq!( 59i32.rounded_div(4),  15); // 59/4 is equal to 14.75 which is closer to 15
assert_eq!( 58i32.rounded_div(4),  15); // 58/4 is equal to 14.5 which is rounded to 15
assert_eq!( 57i32.rounded_div(4),  14); // 57/4 is equal to 14.25 which is closer to 14
assert_eq!(-59i32.rounded_div(4), -15);
assert_eq!(-58i32.rounded_div(4), -15);
assert_eq!(-57i32.rounded_div(4), -14);

License

MIT © Hoàng Văn Khải.

No runtime deps