javascriptmathdivisionmodulus

Getting place values of a number w/ modulus?


(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:

var ones = Math.floor(num % 10),
    tens = Math.floor(num / 10 % 10),
    hundreds = Math.floor(num / 100 % 10),
    thousands = Math.floor(num % 10000 / 1000);

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.


Solution

  •         var ones = Math.floor(num % 10),
                tens = Math.floor(num/10 % 10),
                hundreds = Math.floor(num/100 % 10),
                thousands = Math.floor(num/1000 % 10),
                tenThousands = Math.floor(num / 10000 % 10),
                hundredThousands = Math.floor(num / 100000 % 10),
                millions = Math.floor(num / 1000000 % 10),
                tenMillions = Math.floor(num / 10000000 % 10),
                hundredMillions = Math.floor(num / 100000000 % 10);
    

    Managed to get to 100 million.