i wanted to know if u know how to get the length of digits, like if the user enters 12345 the computer will return 5 because the length is 5
tdoggrme 0 Newbie Poster
Recommended Answers
Jump to PostConvert the digit to a String and get the length.
Integer.toString(number).length();
Jump to PostDouble posted :evil:
http://www.daniweb.com/techtalkforums/thread42510.html
Jump to PostIf you want to do it by hand, here is the algorithm I would use:
int numdigits(int num)
{int len = 0;
while(num >= 10)
{
num = num/10;
len++;
}return len;
}
Do you need this to work only for positive …
All 11 Replies
aniseed 38 Posting Whiz
aniseed 38 Posting Whiz
MIGSoft 0 Posting Pro in Training
hlut 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
hlut 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
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.