For my locale, this seemed to work! This is probably not the most idiomatic rust, but it is functional.
fn readable(mut o_s: String) -> String { let mut s = String::new(); let mut negative = false; let values: Vec<char> = o_s.chars().collect(); if values[0] == '-' { o_s.remove(0); negative = true; } for (i ,char) in o_s.chars().rev().enumerate() { if i % 3 == 0 && i != 0 { s.insert(0, ','); } s.insert(0, char); } if negative { s.insert(0, '-'); } return s } fn main() { let value: i64 = -100000000000; let new_value = readable(value.to_string()); println!("{}", new_value); }
source share