use num_format::{Locale, ToFormattedString};
fn main() {
let s = 1000000.to_formatted_string(&Locale::en);
assert_eq!(&s, "1,000,000");
}
fn main() {
let number = 105359040400;
let formatted = format_number_with_commas(number);
println!("{}", formatted);
}
fn format_number_with_commas(num: u64) -> String {
let num_str = num.to_string();
let mut formatted = String::new();
for (i, c) in num_str.chars().rev().enumerate() {
if i != 0 && i % 3 == 0 {
formatted.insert(0, ',');
}
formatted.insert(0, c);
}
formatted
}