Answers for "find number of digits in a number"

4

how to find how many digits a number has in c++

#include <iostream>
#include <cmath>

unsigned int getNumberOfDigits (int i)
{
    return i > 0 ? log10((double) i) + 1 : 1;
}

int main()
{
	std::cout << "Number of digits: " << getNumberOfDigits(/*Example*/6738) << std::endl;  
	return 0;
}
Posted by: Guest on October-24-2020
5

find number of digits in a number

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

get number of digits in a number

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

Code answers related to "find number of digits in a number"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language