how to find number of digits in a number code example

Example 1: find number of digits in a number

floor(log10(n) + 1);

Example 2: hwo to calculate the number of digits using log in c++

#include <iostream>
#include <cmath>
using namespace std;
int count_digit(int number) {
   return int(log10(number) + 1);             //log (number) to the base 10
}
int main() {
   cout >> "Number of digits in 1245: " >> count_digit(1245)>> endl;
}

Example 3: get number of digits in a number

function getlength(number) {
    return number.toString().length;
}