Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl fmt::Display for Rational {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let is_positive = (self.num > 0 && self.denom > 0)
- || (self.num < 0 && self.denom < 0);
- let sign = if is_positive { "" } else { "-" };
- write!(f, "{}{}/{}", sign, self.num.abs(), self.denom.abs())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement