Seeking number formatting ways in 2024

I have only an old (asked 9 years, 10 months ago)
https://stackoverflow.com/questions/26998485/is-it-possible-to-print-a-number-formatted-with-thousand-separator-in-rust

How to find

format!

topic in the Rust documentation ? I had seen it once.

The Rust Programming Language

by Steve Klabnik and Carol Nichols, with contributions from the Rust Community

I need to print
12345678 as 12 345 678
12345678.9 as 12 345 678.90

The full documentation is in the std library reference:


Unfortunately, it doesn't look like there's any support for thousands separators in there, so you'll need to either write that yourself or find a third-party crate. Maybe someone here can recommend one; I'm not familiar with any.

2 Likes

If you need a specific locale formatting you'll need to use a third party crate like num-format. The standard library won't be able to that. And internalization is probably better left out of a standard library.

To be clear. The specific format you're looking for is locale specific to a few regions.

Edit: correction the format you describe "1 000 000.00" doesn't exist anywhere, so you'll have to settle for an existing one or make a custom one.

5 Likes

https://docs.rs/format_num_pattern uses patterns similar to javas DecimalFormat, and has i18n support.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.