···1315613156 let converted_number = match base {
1315713157 Base::Binary => format!("{minus}0b{:b}", int),
1315813158 Base::Octal => format!("{minus}0o{:o}", int),
1315913159- Base::Decimal => format!("{minus}{}", int),
1316013159 Base::Hexadecimal => format!("{minus}0x{:x}", int),
1316013160+ Base::Decimal => {
1316113161+ format!("{minus}{}", format_int_with_thousands_separator(&int))
1316213162+ }
1316113163 };
1316213164 let title = format!("Convert to `{converted_number}`");
1316313165 self.edits.replace(location, converted_number);
···1317313175 }
1317413176 action
1317513177 }
1317813178+}
1317913179+1318013180+fn format_int_with_thousands_separator(int: &BigInt) -> String {
1318113181+ if int <= &BigInt::from(9999) {
1318213182+ return int.to_string();
1318313183+ }
1318413184+1318513185+ // We get chunks of three digits. If we start from 1234567
1318613186+ // we will have `765`, `432`, `1`
1318713187+ (int.to_string().chars().rev().chunks(3).into_iter())
1318813188+ // Each chunk is turned into a string and those are joined with a
1318913189+ // separator.
1319013190+ .map(|chunk| chunk.collect::<EcoString>())
1319113191+ .join("_")
1319213192+ // And finally reverse everything to bring it back to normal, the number
1319313193+ // is spelled in reverse right now!
1319413194+ .chars()
1319513195+ .rev()
1319613196+ .collect()
1317613197}
13177131981317813199impl<'ast> ast::visit::Visit<'ast> for ConvertIntToDifferentBase<'ast> {