Currency format for display

前端 未结 7 1193
忘了有多久
忘了有多久 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:19

    If you just have the currency symbol and the number of decimal places, you can use the following helper function, which respects the symbol/amount order, separators etc, only changing the currency symbol itself and the number of decimal places to display to.

    public static string FormatCurrency(string currencySymbol, Decimal currency, int decPlaces)
    {
        NumberFormatInfo localFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
        localFormat.CurrencySymbol = currencySymbol;
        localFormat.CurrencyDecimalDigits = decPlaces;
        return currency.ToString("c", localFormat);
    }
    

提交回复
热议问题