CultureInfo.NumberFormat 隐藏逗号
我正在尝试创建一个根本不使用组的 NumberFormat。
我希望显示的所有数字都没有逗号。
例如:
- 1999 而不是 1,999
- 2000000 而不是 2,000,000
- 等等...
不幸的是,我使用的是第 3 方控件,它是一个 NumericEditor,它应用了 CultureInfo 设置来显示逗号。因此,我需要创建一个根本不使用分组的 CultureInfo
实例。
我已经尝试过这个:
int[] groupSize = {0};
CultureInfo culture = new CultureInfo("en-US");
culture.NumberFormat.NumberGroupSizes = groupSize;
另外...
CultureInfo culture = new CultureInfo("en-US");
culture.NumberFormat.NumberGroupSeparator = String.Empty; // Throws and exception with the 3rd party control
我得到的最接近的是...
CultureInfo culture = new CultureInfo("en-US");
culture.NumberFormat.NumberGroupSeparator = " ";
我根本不喜欢这个解决方案,因为它不是逗号而是空格,而且看起来确实很奇怪。
有什么想法吗?
I am trying to create a NumberFormat that will not use Groups at all.
I would like all numbers to be displayed with NO commas.
Example:
- 1999 instead of 1,999
- 2000000 instead of 2,000,000
- etc...
Unfortunately, I am using a 3rd Party control that is a NumericEditor and it applies a CultureInfo setting on it to show commas. So I need to create a CultureInfo
instance that doesn't use Grouping at all.
I have tried this:
int[] groupSize = {0};
CultureInfo culture = new CultureInfo("en-US");
culture.NumberFormat.NumberGroupSizes = groupSize;
Also...
CultureInfo culture = new CultureInfo("en-US");
culture.NumberFormat.NumberGroupSeparator = String.Empty; // Throws and exception with the 3rd party control
The closest I have gotten is...
CultureInfo culture = new CultureInfo("en-US");
culture.NumberFormat.NumberGroupSeparator = " ";
I don't like this solution at all because instead of a comma its white space and it definitely looks odd.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用什么第 3 方控件,您是否尝试过反射(使用 .NET Reflector 之类的东西)来查看它们如何使用 CultureInfo 类,因为在常规的旧 C# 代码中,设置 NumberFormat.NumberGroupSize = new int[]{0 };与 NumberFormat.NumberGroupSeperator = String.Empty; 一样有效。看来第 3 方控件可能以非标准方式使用 CultureInfo 属性。
What 3rd-Party control are you using and have you tried reflecting (using something like .NET Reflector) to see how they are using the CultureInfo class, because in regular old C# code, setting the NumberFormat.NumberGroupSize = new int[]{0}; works as well as NumberFormat.NumberGroupSeperator = String.Empty;. It seems the 3rd Party control might be using the CultureInfo properties in a non-standard way.
考虑实施自定义格式化程序。
您可以像这样分配自定义格式提供程序:
如果他们(第 3 方控件开发人员)没有实现一些“魔法”,这可能会起作用。
Consider implementing custom formatter.
You can assign your custom format provider like this:
That might work if they (3rd party control developers) didn't implement some "magic".