0

If my text reaches 1000 i want it to turn into 1K, and 1200 to be 1.2K. Same with millions. 1000K would turn into 1M, 1100 to turn into 1.1M. Is there anyway to do this. (This is unity c#).

  • Does this answer your question? [Format Number like Stack Overflow (rounded to thousands with K suffix)](https://stackoverflow.com/questions/2134161/format-number-like-stack-overflow-rounded-to-thousands-with-k-suffix) – Max Play Jun 25 '22 at 17:18
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 27 '22 at 01:50

1 Answers1

0

Just create a class that will convert it. I would create a class NumberConverter or something like that and method inside:

    public string GetConvertedNumber(float numb)
    {
    string convertedNumber;
    if(numb < 1000)
    {
       convertedNumber = numb.ToString();
    }
    else if(numb >= 1000 && numb < 1000000)
    {
       convertedNumber = $"{(numb / 1000) Round it to 1 place after dot.ToString()}K"
    }
    }
Wolfik
  • 286
  • 2
  • 7
  • 22