# Capture portions of a number using mathematical operations [closed]

Is there a mathematical way to get the following:

For the the number 777,888,999 so 777 million and etc etc

getMillions(777888999) should return 777 only

getThousands(777888999) should return 888 only

getHundreds(777888999) should return 999 only

This should be done without using regex and without text processing but should be achieved using only mathematical operations.

I'm trying to solve a problem that may be familiar to some which is converting a number expressed in digits to words so 1 -> one, 10 -> ten, 100 -> one hundred etc

My thinking is that if I can convert a number up to 999 then the problem is pretty much solved as the rest will only append the words millions and/or thousands so

777888999 will covert to the words:

777 million and 888 thousands and 999 hundred

of course the above numbers will expressed in words.

This originally was given to me as part of a job interview process about a year ago. I am absolutely not using the solution here for a job application. But the above question is about number manipulation which I'm very interested in.

• Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask. – ratchet freak Mar 7 '14 at 21:01
• What do you get when you divide 777,888,999 by one million and throw away the remainder? – Robert Harvey Mar 7 '14 at 21:03
• This question appears to be off-topic because it is about math. – Robert Harvey Mar 7 '14 at 21:04
• Everything a computer does is math: it computes. – user22815 Mar 7 '14 at 21:26

``````print (777888999/1000000)%1000
• If you don't know how long the number is, you can use `log()` to figure out how many digits are in it. – Sean McSomething Mar 8 '14 at 1:01