How to count the total number of digits in a number with C#

2 Answers

0 votes
using System;

public class Program
{
    public void Main()
    {
        int number = 90862;
		
		int total_digits = (int)Math.Floor(Math.Log10(number) + 1);
         
        Console.WriteLine(total_digits);
    }
}



/*
run:

5

*/

 



answered Dec 30, 2023 by avibootz
0 votes
using System;

public class Program
{
    public void Main()
    {
        int number = 90862;
		
		int total_digits = number.ToString().Length;
         
        Console.WriteLine(total_digits);
    }
}



/*
run:

5

*/

 



answered Dec 30, 2023 by avibootz

Related questions

1 answer 226 views
2 answers 156 views
1 answer 238 views
2 answers 181 views
1 answer 132 views
...