How can I get a count of the total number of digits in a number?(如何计算一个数字的总位数?)
问题描述
如何计算 C# 中数字的总位数?例如,数字 887979789 有 9 位.
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.
推荐答案
不转成字符串也可以试试
Without converting to a string you could try
Math.Floor(Math.Log10(n) + 1);
这篇关于如何计算一个数字的总位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!