Created
October 5, 2022 00:01
-
-
Save gabrielcassimiro/dd0619431900b41ffc33708193e8b59d to your computer and use it in GitHub Desktop.
Use this script to do high value conversions for your games.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Manager | |
{ | |
public static class MonetaryManager | |
{ | |
private static readonly char[] SplitChar = new char[2] { ',', '.' }; | |
public static string ConvertCurrency(double currency) | |
{ | |
return currency switch | |
{ | |
>= 1e+45D => RemoveZero((currency / 1d + 45D).ToString("N1")) + "kk", | |
>= 1e+42D => RemoveZero((currency / 1d + 42D).ToString("N1")) + "jj", | |
>= 1e+39D => RemoveZero((currency / 1d + 39D).ToString("N1")) + "ii", | |
>= 1e+36D => RemoveZero((currency / 1d + 36D).ToString("N1")) + "hh", | |
>= 1e+33D => RemoveZero((currency / 1d + 33D).ToString("N1")) + "gg", | |
>= 1e+30D => RemoveZero((currency / 1d + 30D).ToString("N1")) + "ff", | |
>= 1e+27D => RemoveZero((currency / 1d + 27D).ToString("N1")) + "ee", | |
>= 1e+24D => RemoveZero((currency / 1d + 24D).ToString("N1")) + "dd", | |
>= 1e+21D => RemoveZero((currency / 1d + 21D).ToString("N1")) + "cc", | |
>= 1e+18D => RemoveZero((currency / 1d + 18D).ToString("N1")) + "bb", | |
>= 1e+15D => RemoveZero((currency / 1d + 15D).ToString("N1")) + "aa", | |
>= 1e+12D => RemoveZero((currency / 1d + 12D).ToString("N1")) + "T", | |
>= 1e+9D => RemoveZero((currency / 1d + 9D).ToString("N1")) + "B", | |
>= 1e+6D => RemoveZero((currency / 1d + 6D).ToString("N1")) + "M", | |
>= 1e+3D => RemoveZero((currency / 1d + 3D).ToString("N1")) + "K", | |
_ => currency.ToString("N0") | |
}; | |
} | |
private static string RemoveZero(string value) | |
{ | |
var result = value.Split(SplitChar); | |
return result.Length > 1 && result[1][0] != '0' ? $"{result[0]}.{result[1][0]}" : result[0]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment