Specify a culture in string conversion explicitly
There are different methods of grouping symbols, like 1000; 1 000 and 1'000. Besides there are different digits used for numbers in different countries Chinese numerals
You can see different numbers in Control Panel -> region and language -> Formats -> additional settings -> Standart digits. (Win 7)
比如负数的格式
英文和法语中小数点和千分位的符号不一样DecimalSeparator VS GroupSeparator
Because, for example, English cultures use '.' as a decimal point, where as French cultures use ',' and the opposite to separate thousands.
Specifying a culture removes this ambiguity so that code executes identically on Windows operating systems configured for different languages, particularly if the parsed values are being committed to persistent storage.
[Test] public void TestNumber() { Decimal value = -1234567890.1234789012M; Print("br", value); Print("es-BR", value); Print("pt-BR", value); } static void Print(string cultureName, Decimal value) { CultureInfo cultureInfo = new CultureInfo(cultureName); Console.WriteLine($@"{cultureInfo.Name,-8}{value.ToString("N", cultureInfo.NumberFormat)}"); }
br -1 234 567 890,12 千分位是空格,小数点是逗号
es-BR -1,234,567,890.12 千分位是逗号,小数点是点
pt-BR -1.234.567.890,12 千分位是点,小数点是逗号
导出所有的culture以及对应的NumberFormat
[Test] public void TestCultures() { var array = CultureInfo.GetCultures(CultureTypes.AllCultures); int i = 0; DataTable dataTable=new DataTable(); dataTable.Columns.Add("Order"); dataTable.Columns.Add("Culture"); dataTable.Columns.Add("NumberDecimalSeparator"); dataTable.Columns.Add("NumberGroupSeparator"); dataTable.Columns.Add("DisplayName"); dataTable.Columns.Add("TwoLetterISORegionName"); foreach (var item in array) { i++; var row = dataTable.NewRow(); row["Order"] = i; row["Culture"] = item; row["NumberDecimalSeparator"] = item.NumberFormat.NumberDecimalSeparator; row["NumberGroupSeparator"] = item.NumberFormat.NumberGroupSeparator; try { RegionInfo regionInfo = new RegionInfo(item.Name); row["DisplayName"] = regionInfo.DisplayName; row["TwoLetterISORegionName"] = regionInfo.TwoLetterISORegionName; } catch { } finally { dataTable.Rows.Add(row); } } ExcelConfig excelConfig = new ExcelConfig(); excelConfig.WithHeader = true; var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"{DateTimeOffset.Now:yyyyMMddHHmmssfff}.xlsx"); ExcelHelper.DataTableToExcel(path,excelConfig,dataTable); }