How can I get a count of the total number of digits in a number?

前端 未结 16 1891
春和景丽
春和景丽 2020-11-28 21:28

How can I get a count of the total number of digits of a number in C#? For example, the number 887979789 has 9 digits.

16条回答
  •  隐瞒了意图╮
    2020-11-28 21:53

    Without converting to a string you could try:

    Math.Ceiling(Math.Log10(n));
    

    Correction following ysap's comment:

    Math.Floor(Math.Log10(n) + 1);
    

提交回复
热议问题