Answer the question
In order to leave comments, you need to log in
How to implement infinite balance in Unity?
There is a game, the player has a balance. Pointed it through ulong
but very soon the type overflows. Is it possible to implement an infinite balance, while leaving it with mathematical functions and leaving the possibility of reduction?
example:
105 550 = 105.55K
150 893 945 = 150.89M
etc.
At the moment the abbreviation code is:
public string[] names = { "", "K", "M", "B", "T" };
public string FormatMoney(decimal digit) // Сокращение баланса
{
if(digit == 0)
{
return digit.ToString(CultureInfo.InvariantCulture);
}
else
{
var n = 0;
while (n + 1 < names.Length && digit >= 1000m)
{
digit /= 1000m;
n++;
}
return digit.ToString("#.##") + names[n];
}
}
Answer the question
In order to leave comments, you need to log in
I took a variable of type Double,
That's all the solution to the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question