Files
nadekobot/src/Nadeko.Bot.Common/ICurrencyProvider.cs
Kwoth 2d3ff83c7c * Replacement mechanism reworked
* Services can now register their own replacements
    * Possible bugs and/or backwards-incompatible behavior
2024-04-02 04:25:37 +00:00

29 lines
854 B
C#

using System.Globalization;
using System.Numerics;
namespace NadekoBot.Common;
public interface ICurrencyProvider
{
string GetCurrencySign();
}
public static class CurrencyHelper
{
public static string N<T>(T cur, IFormatProvider format)
where T : INumber<T>
=> cur.ToString("C0", format);
public static string N<T>(T cur, CultureInfo culture, string currencySign)
where T : INumber<T>
=> N(cur, GetCurrencyFormat(culture, currencySign));
private static IFormatProvider GetCurrencyFormat(CultureInfo culture, string currencySign)
{
var flowersCurrencyCulture = (CultureInfo)culture.Clone();
flowersCurrencyCulture.NumberFormat.CurrencySymbol = currencySign;
flowersCurrencyCulture.NumberFormat.CurrencyNegativePattern = 5;
return flowersCurrencyCulture;
}
}