Open gabucito opened 2 years ago
This will be fixed in #2
once merged.
From issue 2
solution:
pub fn pct(&self) -> f32 {
let total = (self.correct + self.wrong) as f32;
if total == 0.0 {
// If total is 0, compiler will see it as NaN
0.0
} else {
(self.correct as f32 / total) * 100.00
}
}
The current pct function shows
%: 1
when it should probably be%: 100
.I would suggest multiplying it to 10,000, round it and then divide it by 100.0 in order to get a percentage up to 2 decimals.
Another way would be to just multiply by 100 and let the print formatted take care of the decimals
Use
{:.2}
so that the print formatted prints up to 2 decimals only