round-to 0.1.5

Round floating point to integer.
Documentation
  • Coverage
  • 100%
    19 out of 19 items documented19 out of 19 items with examples
  • Size
  • Source code size: 30.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.59 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • lkurcak/round-to
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lkurcak

round-to

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);

Implementation

Rounding is implemented using round_ties_even. Floor and ceil use floor and ceil. Values are then converted to target integer type using as.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 or the MIT license https://opensource.org/licenses/MIT, at your option.