如何设置默认CultureInfo.InvariantCulture? [英] How to set CultureInfo.InvariantCulture default?

查看:529
本文介绍了如何设置默认CultureInfo.InvariantCulture?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在C#这样一段代码:

When I have such piece of code in C#:

double a = 0.003;
Console.WriteLine(a);



它打印出0003。

It prints "0,003".

如果我有另一段代码:

double a = 0.003;
Console.WriteLine(a.ToString(CultureInfo.InvariantCulture));



它打印出0.003。

It prints "0.003".

我的问题是,我需要点为十进制的标记,但C#使得逗号作为默认值。此外,我不想类型的代码这么长的行只是为了打印出一个双变量。

My problem is that I need a dot as decimal mark but C# makes a comma as default. Besides I don't want to type such a long line of code just for printing out a double variable.

推荐答案

您可以设置当前线程的文化,任何你想要的文化:

You can set the culture of the current thread to any culture you want:

Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;



需要注意的是改变企业文化也影响之类的字符串比较和排序,日期格式和日期的解析和数字。

Note that changing the culture also affects things like string comparison and sorting, date formats and parsing of dates and numbers.

这篇关于如何设置默认CultureInfo.InvariantCulture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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