【问题标题】:How to get default decimal / thousand separator for current locale in .net如何在.net中获取当前语言环境的默认小数/千位分隔符
【发布时间】:2015-09-02 04:47:12
【问题描述】:

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

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

有没有类似日期/时间的方法?

【问题讨论】:

  • 搜索标题bing.com/…MSDN link 置于最佳结果中...您确实应该考虑选择您正在使用的更好的搜索引擎。
  • @AlexeiLevenkov,您的链接只给出了数据类型,仍然需要从某个地方请求它,这是重要的部分(因此下面的 NumberFormat)。也许搜索引擎的评论是不合理的:)
  • @AlexeiLevenkov 嘿,谷歌把我带到了这里,第一个(和接受的答案)无论如何都是正确的。 :-)

标签: c# asp.net asp.net-mvc-3 localization


【解决方案1】:

NumberFormat 属性包含货币和数字的此信息。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      通过这段代码可以得到当前的系统设置:

      System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
      FORMAT_NUMBER_DECIMALSEPARATOR = ci.NumberFormat.CurrencyDecimalSeparator;
      FORMAT_NUMBER_DIGITGROUP = ci.NumberFormat.CurrencyGroupSeparator;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-09
        • 2014-08-09
        • 2016-01-14
        • 1970-01-01
        • 2017-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多