diff --git a/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs b/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs index f2fd050..c96f74a 100644 --- a/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs +++ b/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs @@ -82,14 +82,14 @@ public static class StringExtensions // Step 3 for (var i = 1; i <= n; i++) //Step 4 - for (var j = 1; j <= m; j++) - { - // Step 5 - var cost = t[j - 1] == s[i - 1] ? 0 : 1; + for (var j = 1; j <= m; j++) + { + // Step 5 + var cost = t[j - 1] == s[i - 1] ? 0 : 1; - // Step 6 - d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); - } + // Step 6 + d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); + } // Step 7 return d[n, m]; @@ -147,4 +147,5 @@ public static class StringExtensions var newString = str.UnescapeUnicodeCodePoint(); return newString; }); + } \ No newline at end of file diff --git a/src/EllieBot/_common/_Extensions/NumberExtensions.cs b/src/EllieBot/_common/_Extensions/NumberExtensions.cs index 3e0f703..3e28588 100644 --- a/src/EllieBot/_common/_Extensions/NumberExtensions.cs +++ b/src/EllieBot/_common/_Extensions/NumberExtensions.cs @@ -1,7 +1,30 @@ +using System.Globalization; + namespace EllieBot.Extensions; public static class NumberExtensions { public static DateTimeOffset ToUnixTimestamp(this double number) => new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).AddSeconds(number); + + public static string ToShortString(this decimal value) + { + if (value <= 1_000) + return Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); + if (value <= 1_000_000) + return Math.Round(value, 1).ToString(CultureInfo.InvariantCulture); + var tokens = " MBtq"; + var i = 2; + while (true) + { + var num = (decimal)Math.Pow(1000, i); + if (num > value) + { + var num2 = (decimal)Math.Pow(1000, i - 1); + return $"{Math.Round((value / num2), 1)}{tokens[i - 1]}".Trim(); + } + + i++; + } + } } \ No newline at end of file