I'm asking myself, "what is the best way to create a money system in Unity with C# and money stages just like this game does?".
I already have some code (that doesn't work the way I want) that kinda does this, but it doesn't feel right to do it this way... There is always a small thought, that this won't work, because the max int number is 2.147.483.647
ant I definetly want to go higher than that.
public string moneyFormatter (int num)
{
if (num >= 1000000000)
return (num / 1000000).ToString("#,0B");
if (num >= 100000000)
return (num / 1000000000).ToString("0.#") "B";
if (num >= 10000000)
return (num / 1000000).ToString("#,0M");
if (num >= 1000000)
return (num / 1000000).ToString("0.#") "M";
if (num >= 100000)
return (num / 1000).ToString("#,0K");
if (num >= 10000)
return (num / 1000).ToString("#,0K");
return num.ToString("#,0");
}
Am I already doing it completely wrong?
CodePudding user response:
Most of these games use Floating-point like double
which can give you up to more than 10^308 at the cost of precision.
If you want precision but with the cost of speed and memory usage, check out BigInteger.