如何在.net中获取当前语言环境的默认十进制/千位分隔符

问题描述 投票:2回答:3

根据目前的文化,我需要千位和小数分隔符。如果我们使用的是美国文化,那么对于小数,它应该是“。”它应该','。但是对于德国文化,默认的小数分隔符是','和千分隔符是'。'。获取日期时间分隔符我正在使用以下代码

               CultureInfo us = new CultureInfo("en-US");
                string shortUsDateFormatString = us.DateTimeFormat.ShortDatePattern;
                string dateseparator= us.DateTimeFormat.DateSeparator;
                string timeseparator= us.DateTimeFormat.TimeSeparator;

有没有像日期/时间一样的东西?

c# asp.net asp.net-mvc-3 localization
3个回答
7
投票

NumberFormat属性有货币和数字的这个信息。


6
投票

您可以使用NumberFormatCultureInfo属性,其中包含小数分隔符和千位分隔符的属性

var numberFormat = us.NumberFormat;
string decimalSeparator = numberFormat.NumberDecimalSeparator;
string thousandsSeparator = numberFormat.NumberGroupSeparator;

1
投票

通过此代码可以获得当前的系统设置:

System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
FORMAT_NUMBER_DECIMALSEPARATOR = ci.NumberFormat.CurrencyDecimalSeparator;
FORMAT_NUMBER_DIGITGROUP = ci.NumberFormat.CurrencyGroupSeparator;
© www.soinside.com 2019 - 2024. All rights reserved.