Compare commits
5 Commits
62f4943bdb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fea33ca70 | |||
| c16472d857 | |||
| 0d5511b4eb | |||
| 7387fba90f | |||
| 885bbfeebe |
@@ -1,6 +1,6 @@
|
|||||||
use std::{fmt, ops};
|
use std::{fmt, ops};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)]
|
||||||
pub struct Fraction {
|
pub struct Fraction {
|
||||||
num: i64,
|
num: i64,
|
||||||
den: i64,
|
den: i64,
|
||||||
@@ -158,7 +158,11 @@ impl ops::Neg for Fraction {
|
|||||||
|
|
||||||
impl fmt::Display for Fraction {
|
impl fmt::Display for Fraction {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{0}/{1}", self.num, self.den)
|
if self.den == 1 {
|
||||||
|
return write!(f, "{0}", self.num);
|
||||||
|
} else {
|
||||||
|
return write!(f, "{0}/{1}", self.num, self.den);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user