Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

currentculture - C# doubles show comma instead of period

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try to use

double.Parse("...", CultureInfo.InvariantCulture)

and

x.ToString(CultureInfo.InvariantCulture)

in the parts of the program that you are positive you need to have decimal period instead of comma or other regional settings dependent decimal separator.

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...