rustc_data_structures/thousands/
mod.rs

1//! This is an extremely bare-bones alternative to the `thousands` crate on
2//! crates.io, for printing large numbers in a readable fashion.
3
4#[cfg(test)]
5mod tests;
6
7// Converts the number to a string, with underscores as the thousands separator.
8pub fn format_with_underscores(n: usize) -> String {
9    let mut s = n.to_string();
10    let mut i = s.len();
11    while i > 3 {
12        i -= 3;
13        s.insert(i, '_');
14    }
15    s
16}