Formatting numbers in different cultures

后端 未结 2 484
感动是毒
感动是毒 2020-12-18 10:19

Assuming an invariant culture, is it possible to define a different group separator in the format - than the comma?

Thread.CurrentThread.Cur         


        
相关标签:
2条回答
  • 2020-12-18 10:51

    When you have different format strings, this does not mean that you have to use InvariantCulture. If you have a format string for germany e.g. you format this string using the Culture("de-de"):

    String.Format(CultureInfo.GetCultureInfo( "de-de" ), "{0:0},-", 2295) //will result in 2.295,-
    String.Format(CultureInfo.GetCultureInfo( "en-us" ), "{0:0},-", 2295) //will result in 2,295,-
    

    Alternatively you can specify your custom number format info:

    NumberFormatInfo nfi = new NumberFormatInfo( )
    {
        CurrencyGroupSeparator = ":"
    };
    String.Format(nfi, "{0:0},-", 2295) //will result in 2:295,-
    
    0 讨论(0)
  • 2020-12-18 11:17

    The normal approach would be to not use an Invariant culture.

    You do specify the formatting in Invariant style, but the proper symbols would be substituted, #,##0.00 will come out as 1.234,50 or as 1,235.50 depending on the actual culture used.

    0 讨论(0)
提交回复
热议问题