I need to store the number of digits from a number into a variable. e.g. 538, i need to store 3. How can I accomplish this is C++? Thanks.
lewashby
56
Junior Poster
Recommended Answers
Jump to PostHere is something to start with:
int getNrDigits(int my_int) { int local_int = my_int; int count = 0; while (local_int > 0) { local_int /= 10; count++; } return count; }
I hope I didn't missed anything because this was programming on paper at late hour …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.