How to get specific culture currency pattern

前端 未结 7 1993
一向
一向 2020-12-16 11:35

How do i get the currency pattern for a specific culture?

For Example:

Instead of using:

string.Format(\"{0:c}\", 345.10)

I

7条回答
  •  一整个雨季
    2020-12-16 11:52

    I think what you're asking is how to change the currency symbol but keep the culture-specific formatting. You can do this by getting a copy of the current NumberFormatInfo and modifying the CurrencySymbol property:

    Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
    // pretend we are german
    
    var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
    nfi.CurrencySymbol = "$$$";
    Console.WriteLine(string.Format(nfi,"{0:c}",345.10));
    

    This will output:

    345,10 $$$
    

    Without changing the CurrentCulture it outputs (for me):

    $$$345.10
    

提交回复
热议问题