Closed
Description
extern crate num;
use num::rational::BigRational;
fn main() {
let x = from_str::<BigRational>("2/5").unwrap();
println!("{}, {}", x, x.round());
}
Prints "2/5, 1".
The method is written here:
http://static.rust-lang.org/doc/master/src/num/home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libnum/rational.rs.html#138-140
pub fn round(&self) -> Ratio<T> {
if *self < Zero::zero() {
Ratio::from_integer((self.numer - self.denom + One::one()) / self.denom)
} else {
Ratio::from_integer((self.numer + self.denom - One::one()) / self.denom)
}
}
Metadata
Metadata
Assignees
Labels
No labels