Skip to content

Instantly share code, notes, and snippets.

@olsonjeffery
Created May 26, 2014 03:07
Show Gist options
  • Save olsonjeffery/af7cf58d560c83e8f2c9 to your computer and use it in GitHub Desktop.
Save olsonjeffery/af7cf58d560c83e8f2c9 to your computer and use it in GitHub Desktop.
kludge
pub fn print(v: &BigRational) -> ~str {
match v.is_integer() {
true => v.numer().to_str(),
false => {
let whole_val = v.numer() / *v.denom();
let remainder_val = v.numer() % *v.denom();
let denom_fl: f64 = FromStr::from_str(v.denom().to_str())
.expect("should be able to convert denom to float");
let remainder_fl: f64 = FromStr::from_str(remainder_val.to_str())
.expect("should be able to convert remainder to float");
let decimal_val = remainder_fl / denom_fl;
format!("{}.{}", whole_val.to_str(),
decimal_val.to_str().slice_from(2).to_owned())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment