mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-04 08:34:27 -05:00
add: Added .coins command which lists top 10 cryptos ordered by marketcap, paginated with 10 per page
This commit is contained in:
@@ -147,4 +147,5 @@ public static class StringExtensions
|
||||
var newString = str.UnescapeUnicodeCodePoint();
|
||||
return newString;
|
||||
});
|
||||
|
||||
}
|
||||
@@ -1,7 +1,30 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace NadekoBot.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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user