Answer the question
In order to leave comments, you need to log in
Reducing large numbers in Unity3D. How to do it?
There is a number of type decimal in C#.
Conditionally 1,000,000,000,000
It is desirable to display it in the form of 1T (Trilion), while it is desirable that there be the possibility of such a display:
1,250,000,000,000 = 1.25T
I have already rummaged through many articles, but have not found a solution.
How can such a reduction be implemented?
1000 = 1K || 1 250 = 1.25K
1 000 000 = 1M || 1,250,000 = 1.25M
etc.
Everything I could find, but it doesn't work very well.
char[] names = { 'K', 'M', 'B', 'T', ...};
private string __CutDigit(string digit)
{
var dotIdx = digit.IndexOf('.');
if (dotIdx < 0) dotIdx = digit.Length;
var triples = dotIdx / 3;
var num = dotIdx % 3;
return digit.Substring(0, num) + '.' + digit[num] + names[triples];
}
Answer the question
In order to leave comments, you need to log in
static string[] names = { "", "K", "M", "B", "T" };
static string FormatMoney(decimal digit)
{
int n = 0;
while (n + 1 < names.Length && digit >= 100m)
{
digit /= 1000m;
n++;
}
return string.Format("{0}{1}", digit, names[n]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question