How can I count the digits in an integer without a string cast?

前端 未结 10 1144
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 00:54

I fear there\'s a simple and obvious answer to this question. I need to determine how many digits wide a count of items is, so that I can pad each item number with the m

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 01:33

    I would have posted a comment but my rep score won't grant me that distinction.

    All I wanted to point out was that even though the Log(10) is a very elegant (read: very few lines of code) solution, it is probably the one most taxing on the processor.

    I think jherico's answer is probably the most efficient solution and therefore should be rewarded as such.

    Especially if you are going to be doing this for a lot of numbers..

提交回复
热议问题