Thread: counting digits
View Single Post
Old Apr 10th, 2007, 10:42 AM   #2
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
Well you have one obvious option which would be convert to a string and count the characters (possibly accounting for leading zeros depending on your task).

Another option might be to test the int against being less than 10, 100, 1000, etc. The max size for a int will mean you won't have to perform countless comparisons.

Finally you could look into log's, particularly log10 of the int.
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote