Skip to content

Commit

Permalink
Write the HumanCount implementation with enumerate()
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster authored and djc committed Dec 30, 2021
1 parent 41a0a10 commit 92ce4c3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/format.rs
Expand Up @@ -134,11 +134,11 @@ impl fmt::Display for HumanCount {
use fmt::Write;

let num = self.0.to_string();
let mut i = num.len();
for c in num.chars() {
let len = num.len();
for (idx, c) in num.chars().enumerate() {
let pos = len - idx - 1;
f.write_char(c)?;
i -= 1;
if i > 0 && i % 3 == 0 {
if pos > 0 && pos % 3 == 0 {
f.write_char(',')?;
}
}
Expand Down

0 comments on commit 92ce4c3

Please sign in to comment.