How can i figure out the number of numbers in an int value
IE
12345 has 5 numbers in it.
Need this beacause i'm making a simple method to convort a int to a string;
Printable View
How can i figure out the number of numbers in an int value
IE
12345 has 5 numbers in it.
Need this beacause i'm making a simple method to convort a int to a string;
Repeat division (with truncation) by 10 until you get 0.
12345 / 10 = 1234
1234 / 10 = 123
123 / 10 = 12
12 / 10 = 1
1 / 10 = 0
5 divisions => 5 digits
Thanks. i shall put it to good use. loop it till it equals 0 :D
You can also take the base 10 log and round to the next highest integer (actually, take the log, cast to an int, and add 1). That would probably be faster.
will try that. got some code almost work using this method so i might just stick to this.. although speed is always better