Created
May 26, 2014 03:07
-
-
Save olsonjeffery/af7cf58d560c83e8f2c9 to your computer and use it in GitHub Desktop.
kludge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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