C#双打显示逗号而不是周期 [英] C# doubles show comma instead of period

查看:150
本文介绍了C#双打显示逗号而不是周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎有同样的问题,因为在这个线程的家伙:



http://stackoverflow.com/questions/359298/convert-float-that-has-period-instead-of-comma



所以,我的

 双X = 234.4; 
串Y = x.ToString();



我得到Ÿ==234,4;



更糟糕的是... Double.Parse(234.4)抛出异常

我写的代码,很多之前,我被要求使用期限,而不是逗号,所以我宁愿一些方法来改变我的CultureInfo在全球范围



有没有在一些项目设置,我可以做什么?



我试过

  Application.CurrentCulture = CultureInfo.CreateSpecificCulture(EN-US); 
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(EN-US);
Thread.CurrentThread.CurrentUICulture =新的CultureInfo(EN-US);



他们工作的一种。他们应用程序的大部分工作,但驻留在我的TabControl的标签仍然要使用我的电脑本地化的CultureInfo



<所有控件p >关于如何解决此问题?


解决方案

感谢林Sabaus评论我找到了解决办法,这是放置

  Application.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(EN-US); 



在main()之前,我建立了我的表。



现在我不会改变我所有的ToString()和Double.Parse():-) Yey!


I almost have the same problem as the guy in this thread:

http://stackoverflow.com/questions/359298/convert-float-that-has-period-instead-of-comma

So that my

double x = 234.4;
string y = x.ToString();

I get y == "234,4";

Even worse ... Double.Parse("234.4") throws an exception.

I have written alot of code before I was asked to use period instead of comma, so I would prefer to have some way to change my CultureInfo at a global level.

Is there some setting in the projects that I can do?

I've tried:

        Application.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

They kind of work. They work for most part of the application, but all controls that reside in the tabs of my TabControl still wants to use my computers Localized CultureInfo.

Any Ideas on how to solve this?

解决方案

Thanks to Florin Sabaus comment I found the solution, which was to place

        Application.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

in Main() right before I created my form.

Now I won't have to change all my .ToString() and Double.Parse() :-) Yey!

这篇关于C#双打显示逗号而不是周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆