是否可以在 Rust 中打印用千位分隔符格式化的数字? [英] Is it possible to print a number formatted with thousand separator in Rust?
本文介绍了是否可以在 Rust 中打印用千位分隔符格式化的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如
println!("{}", 10_000_000);
结果
10000000
而我想将其格式化为类似
whereas I'd like to format it to look something like
10,000,000
我浏览了fmt
模块文档,但没有什么可以涵盖这种特殊情况.我认为这样的事情会奏效
I went through the fmt
module documentation, but there's nothing to cover this particular situation. I thought something like this would work
println!("{:,i}", 10_000_000);
但它抛出一个错误
invalid format string: expected `}`, found `,`
推荐答案
num_format crate 将为您解决这个问题.添加您的语言环境,它会发挥作用.
The num_format crate will solve this issue for you. Add your locale and it will do the magic.
这篇关于是否可以在 Rust 中打印用千位分隔符格式化的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文