如何在 C# 中格式化数字,使 12523 变为“12K”,2323542 变为“2M”等?
如何在 C# 中格式化数字,使 12523.57 变为“12K”,2323542.32 变为“2M”等?
我不知道如何附加正确的数字缩写(K、M 等)并显示适当的数字?
那么,
1000 = 1K
2123.32 = 2K
30040 = 30k
2000000 = 2M
C# 中有内置方法可以做到这一点吗?
Possible Duplicate:
Format Number like StackoverFlow (rounded to thousands with K suffix)
How can I format numbers in C# so 12523.57 becomes "12K", 2323542.32 becomes "2M", etc?
I don't know how to append the correct number abbreviation (K, M, etc) and show the appropriate digits?
So,
1000 = 1K
2123.32 = 2K
30040 = 30k
2000000 = 2M
Is there a built in way in C# to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为这是 C#/.Net 中的标准功能,但自己做到这一点并不困难。在伪代码中,它会是这样的:
如果您不想截断,而是舍入,请使用舍入而不是取整。
I don't think this is standard functionality in C#/.Net, but it's not that difficult to do this yourself. In pseudocode it would be something like this:
If you don't want to truncate, but round, use round instead of floor.
没有内置的方法,你必须推出自己的例程,类似于:
There's no built in way, you'll have to roll your own routine, similar to this: