From ff41f79dd8c7f76a048182c462843660c78bf589 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sat, 22 Jan 2022 13:17:52 +0100 Subject: [PATCH] improve formatting of numbers --- Credits.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Credits.cs b/Credits.cs index 53790d5..e8899b6 100644 --- a/Credits.cs +++ b/Credits.cs @@ -3,13 +3,25 @@ namespace EDJournal { public class Credits { public static string FormatCredits(int amount) { + return FormatCredits((long)amount); + } + + public static string FormatCredits(long amount) { var format = new CultureInfo(CultureInfo.CurrentCulture.Name, true).NumberFormat; format.NumberGroupSeparator = ","; + format.NumberDecimalSeparator = "."; format.NumberGroupSizes = new int[1] { 3 }; - format.NumberDecimalDigits = 0; - if (amount > 0 && (amount % 1000000) == 0) { + format.NumberDecimalDigits = 1; + 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) { amount /= 1000000; return string.Format("{0}M CR", amount.ToString("N", format)); + } 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)); } else if (amount > 0 && (amount % 1000) == 0) { amount /= 1000; return string.Format("{0}K CR", amount.ToString("N", format));