Answers for "How to compute the number of digits of a number ?"

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;
}
Posted by: Guest on May-26-2020
6

find number of digits in a number

floor(log10(n) + 1);
Posted by: Guest on February-20-2021
1

calc the number of digits

int count = 0;
int n = number;

while (n != 0)
{
    n /= 10;
    cout++;
}
Posted by: Guest on June-08-2021
0

get number of digits in a number

function getlength(number) {
    return number.toString().length;
}
Posted by: Guest on May-11-2021
0

number of digits calculation

number_of_digits = 0
    a_variable = input
    while a_variable >= 1:
        number_of_digits += 1
        a_variable /= 10
#Just translated Kind Kinkajou's answer to python.
#Please support him.
#Profile link: https://www.codegrepper.com/app/profile.php?id=341732
Posted by: Guest on August-10-2021

Code answers related to "How to compute the number of digits of a number ?"

Browse Popular Code Answers by Language