不要改变'。'到','当文化发生变化时

时间:2018-04-26 10:29:24

标签: c# asp.net culture

当我更改1.0时,我有一个网页,例如2,0转为Culture。您可以在更改Culture时阻止这种情况发生吗?

1 个答案:

答案 0 :(得分:2)

您可以在所使用的文化中选择您想要的(数字)DecimalSeperator:

double number = 2.4;

CultureInfo culture = Thread.CurrentThread.CurrentCulture;
// Make a writable clone
culture = (CultureInfo)culture.Clone();
culture.NumberFormat.NumberDecimalSeparator= ".";
Thread.CurrentThread.CurrentCulture = culture;
System.Console.WriteLine(number); //prints 2.4

culture.NumberFormat.NumberDecimalSeparator = ",";
Thread.CurrentThread.CurrentCulture = culture;
System.Console.WriteLine(number); //prints 2,4

还有号码分组:

number = 123232;
culture.NumberFormat.NumberGroupSeparator= ",";
Thread.CurrentThread.CurrentCulture = culture;
System.Console.WriteLine(number); //prints 123,232