Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math, largest number

Tags:

c#

math

does anyone know of a Math method that returns the largest number of a given number of digits.

e.g The largest number using 1 digit is 9, 2 is 99, 3 is 999, 4 is 9999 .... and so on.

It is easily achievable using strings however this is not quite what I am looking for.

  private double GetLargestNumber(int numOfDigits)
    {
        string max = "";
        for (int i = 1; i <= numOfDigits; i++)
        {
            max += "9";
        }
        return Convert.ToDouble(max);

    }

Thanks in advance.

like image 880
John Avatar asked Sep 22 '26 04:09

John


1 Answers

return Math.Pow(10, numOfDigits) - 1;
like image 89
Marc Gravell Avatar answered Sep 24 '26 19:09

Marc Gravell