How to find a number inside another number and show at which decimal place the number occurs?

Hi everyone!

like I wrote in the title, I would like to know how to find a number inside another number and show at which decimal place the number occurs?

For example:

We have the number PI:


And then we have another number, for example this one:


Now I want to know on which decimal place exactly this number occurs

The Answer is: 1-5

Because the number we are looking for is showing up on the first decimal place and end on the fifth decimal place. As you can see here:


I would like to write a small program with an input field and an output field

Input: Type in any number
Output: Show at what decimal place the number occurs

The funny thing is that I think it should be not that hard to program a query to find the numbers easily. However I dont know where to start…

I guess we need to make a const Pi and then we need to define a random number let OtherNumber. We loop though const PI and check if (if statement) the random number we need to loop though is somewhere available inside of the number PI. Then we need to declare that if (if Statement) this number is showing up then display the decimal place at one which the number occurs.

These are my thoughts right now and I would really aprechiate if someone with more experience can let me know his / her thought process.

Thanks for answers!


Convert it to string and search inside it? I would use string.indexOf()


@camperextraordinaire Yes that is correct :slight_smile:

@skaparate That sounds easy lol… and when I have the index I need to add the number of digits from the second number and then I have the answer…

It sounds easy, however I also need an input field to be able to type in the number and then find the index and calculate the digits from the input number…

I will try it tomorrow

1 Like

Hi everyone!

Thanks to @camperextraordinaire he showed me an easy way to find a number simply with the use of IndexOf. Here is the solution:

It works great, however I need to find the decimal place for 1 000 000 numbers and I dont want to type in all numbers by myself lol :joy:

Is there any way to automate these numbers and save the result inside a CSV file?

Here is how I would do it (theoretically):

We need to generate an array with the numbers 1 - 999 999 and then we need to execute the calculation for each number. Therefore we need to loop though the array we created and then add each single number inside the field “Number to find”, afterwards we want to execute the calculation and save the result inside an online CSV file (for example Google Docs). This should be done for each single number until we reached the end of the array.

Is this the correct way to automate an array of numbers?

Can everything be done with vanilla JS only?

Thanks again for help! :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.