Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check the number of digits in an integer 1

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
0
0
IL
Hello,

I have an arbitrary int value and I would like to check how many digits this integer has (For example: 367 has 3 digits...). How can I do it?
 
Note that integers can be negative, so the solution posted above, which basically just counts how many characters are required to render the integer as text will not work for negative integers (as the first character will be the '-' character indicating a negative number).

I suggest taking the absolute value of the integer (so if it is -ve it will become positive, and if it is +ve it will not be changed) and then applying the above method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top