about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/thousands/mod.rs
blob: e7ab7ec2932df8dd656f9aaf93c8ff3e4394958e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! This is an extremely bare-bones alternative to the `thousands` crate on
//! crates.io, for printing large numbers in a readable fashion.

#[cfg(test)]
mod tests;

// Converts the number to a string, with underscores as the thousands separator.
pub fn format_with_underscores(n: usize) -> String {
    let mut s = n.to_string();
    let mut i = s.len();
    while i > 3 {
        i -= 3;
        s.insert(i, '_');
    }
    s
}