当我更改1.0
时,我有一个网页,例如2,0
转为Culture
。您可以在更改Culture
时阻止这种情况发生吗?
答案 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