edjournal/Credits.cs

34 lines
1.4 KiB
C#
Raw Permalink Normal View History

2021-08-25 18:24:44 +02:00
using System.Globalization;
namespace EDJournal {
public class Credits {
public static string FormatCredits(int amount) {
2022-01-22 13:17:52 +01:00
return FormatCredits((long)amount);
}
public static string FormatCredits(long amount) {
2021-08-27 22:37:06 +02:00
var format = new CultureInfo(CultureInfo.CurrentCulture.Name, true).NumberFormat;
2021-08-27 22:15:56 +02:00
format.NumberGroupSeparator = ",";
2022-01-22 13:17:52 +01:00
format.NumberDecimalSeparator = ".";
2021-08-27 22:15:56 +02:00
format.NumberGroupSizes = new int[1] { 3 };
format.NumberDecimalDigits = 0;
2022-01-22 13:17:52 +01:00
if (amount > 0 && (amount % 1000000000) == 0) {
amount /= 1000000000;
return string.Format("{0}M CR", amount.ToString("N", format));
} else if (amount > 0 && (amount % 1000000) == 0) {
2021-08-25 18:24:44 +02:00
amount /= 1000000;
2021-08-27 22:37:06 +02:00
return string.Format("{0}M CR", amount.ToString("N", format));
2022-01-22 13:17:52 +01:00
} else if (amount > 0 && (amount % 100000) == 0) {
double am = ((double)amount) / 1000000;
format.NumberDecimalDigits = 1;
return string.Format("{0}M CR", am.ToString("N", format));
2021-08-28 00:56:32 +02:00
} else if (amount > 0 && (amount % 1000) == 0) {
2021-08-25 18:24:44 +02:00
amount /= 1000;
2021-08-27 22:37:06 +02:00
return string.Format("{0}K CR", amount.ToString("N", format));
2021-08-25 18:24:44 +02:00
}
2021-08-27 22:37:06 +02:00
return string.Format("{0} CR", amount.ToString("N", format));
2021-08-25 18:24:44 +02:00
}
}
}