Skip to content
Advertisement

Getting place values of a number w/ modulus?

  • I need to get the place value of a random number submitted by a user. This number can by anything from 0-1000000000000000 (zero to one trillion).

  • I think this can be achieved by using the JavaScript modulus % operator. The problem, I don’t really know how to use it, nor do I understand it.

  • Here is the Fiddle.

(All I know is 10%3 returns 1 because 3*3 = 9 and 10-9 = 1)

I figured out the ones, tens, hundreds, and thousands:

JavaScript

I just need:

  1. Ten thousands
  2. Hundred thousands
  3. Millions
  4. Ten millions
  5. Hundred millions
  6. Billions
  7. Ten billions
  8. Hundred billions
  9. Trillions

— I don’t even know if this is possible for the rest, but if you have any hints or find at least one, let me know! Thank you.

Advertisement

Answer

JavaScript

Managed to get to 100 million.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement