Once a numeric number is calculated, basically it is constantly splitting using 10. Re-count and see how many numbers there are.
Today it is easier to think about converting numbers to strings and then getting the number of digits by String.Length.
String num2str1 (unsigned int num) {stringstream ss;ss<<num;return ss.str ();} String num2str2 (unsigned int num) {char str_[10];sprintf_s (str_, "%d", num); string str = Str_;return str;} < directly calculates the number of digits unsigned int getLenOfNum1 (unsigned int num) {unsigned int counter = 1;while (NUM/10) {counter++;num = num/ 10;} return counter;} < Convert to string first. Then calculate the number of bits unsigned int getLenOfNum2 (unsigned int num) {return num2str1 (num). Length ();}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Duanxx C + + learns: The number of digits calculated