D
D
dark_spectator2019-01-25 09:21:12
C++ / C#
dark_spectator, 2019-01-25 09:21:12

How to implement infinite balance in Unity?

There is a game, the player has a balance. Pointed it through ulongbut 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

3 answer(s)
#
#, 2019-01-25
@dark_spectator

https://duckduckgo.com/?q=Unity+biginteger

D
dark_spectator, 2019-01-25
@dark_spectator

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 question

Ask a Question

731 491 924 answers to any question