Currency format for display

前端 未结 7 1189
忘了有多久
忘了有多久 2020-11-27 06:50

Is there a way to format the correct currency representation for a country?

Example UK -£127.54 Netherlands € 127,54- USA $127.54

etc..

Some things to

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 07:09

    Try the Currency Format Specifier ("C"). It automatically takes the current UI culture into account and displays currency values accordingly.

    You can use it with either String.Format or the overloaded ToString method for a numeric type.

    For example:

    double value = 12345.6789;
    Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));
    
    Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));
    
    Console.WriteLine(value.ToString("C3", CultureInfo.CreateSpecificCulture("da-DK")));
    
    // The example displays the following output on a system whose
    // current culture is English (United States):
    //       $12,345.68
    //       $12,345.679
    //       kr 12.345,679
    

提交回复
热议问题