如何计算数字中的总位数? [英] How can I get a count of the total number of digits in a number?

查看:19
本文介绍了如何计算数字中的总位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算 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);

这篇关于如何计算数字中的总位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆