<![CDATA[Math Is Fun Forum / how can we find the first digit of a number using log10]]> 2022-01-25T18:25:48Z FluxBB https://www.mathisfunforum.com/viewtopic.php?id=27059 <![CDATA[Re: how can we find the first digit of a number using log10]]> hi

It's all due to the definition of log base 10

If

So let's look at some integer cases first:

x = 1  y = 10
x = 2  y = 100
x = 3  y = 1000

and

x = 0    y = 1
x = -1   y = 0.1
x = -2   y = 0.01
x = -3   y = 0.001

Now for a number like eg. 53

and so on.

So numbers between 1 and 10        have a log that is between 0 and 1
numbers between 10 and 100    have a log that is between 1 and 2
numbers between 100 and 1000 have a log that is between 2 and 3

For your example 123456 = 1.23456 x 10^5 so the log will be 5.something

Bob

some back ground here: https://www.mathsisfun.com/algebra/logarithms.html

]]>
https://www.mathisfunforum.com/profile.php?id=67694 2022-01-25T18:25:48Z https://www.mathisfunforum.com/viewtopic.php?pid=423149#p423149
<![CDATA[how can we find the first digit of a number using log10]]> Hi,
int number 123456;
int firstDigit;
int totalDigits = (int) Math.log10(number);
firstDigit = (int) (number/ (int) Math.pow(10,totalDigits));
System.out.println("First Digit is: " + firstDigit);

how could log10 of a number like 123456 is 5?
I type that in google and it's 5.09151220163 not 5, I know we used casting so it discard the fractional parts to get 5, but my question is not about the Java it's about log10 why log10 always get the total digits with fractional parts always!
like log10 of 532 is 2.7259116323 which is 2 digits that is working! but how mathematically is that

how can Math.log10(12345) calculate the number of digits which is 5 correct!?
only that first part of the code is really ambiguous

]]>
https://www.mathisfunforum.com/profile.php?id=212310 2022-01-25T16:17:42Z https://www.mathisfunforum.com/viewtopic.php?pid=423148#p423148