diff --git a/src/lib.rs b/src/lib.rs index 4564565..3b00676 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,7 @@ -use std::{fmt, ops}; +use std::{ + fmt::{self, write}, + ops, +}; #[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)] pub struct Fraction { @@ -158,7 +161,11 @@ impl ops::Neg for Fraction { impl fmt::Display for Fraction { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{0}/{1}", self.num, self.den) + if self.num > 1 { + return write!(f, "{0}/{1}", self.num, self.den); + } else { + return write!(f, "{0}", self.num); + } } }