patternrustModerate
Is it possible to print a number formatted with thousand separator in Rust?
Viewed 0 times
possiblewithprintthousandnumberrustformattedseparator
Problem
For instance
results in
whereas I'd like to format it to look something like
I went through the
but it throws an error
println!("{}", 10_000_000);results in
10000000
whereas I'd like to format it to look something like
10,000,000
I went through the
fmt module documentation, but there's nothing to cover this particular situation. I thought something like this would workprintln!("{:,i}", 10_000_000);but it throws an error
invalid format string: expected }, found ,
Solution
The num_format crate will solve this issue for you. Add your locale and it will do the magic.
Context
Stack Overflow Q#26998485, score: 29
Revisions (0)
No revisions yet.