Mat*_*hew 4 javascript math division modulus
我需要获取用户提交的随机数的位置值.这个数字可以是0-1000000000000000 (零到一万亿).
我认为这可以通过使用JavaScript模%
运算符来实现.问题,我真的不知道如何使用它,也不了解它.
这是小提琴.
(我所知道的是10%3返回1因为3*3= 9和10-9= 1)
我想出了数十,数百和数千:
var ones = Math.floor(num % 10),
tens = Math.floor(num / 10 % 10),
hundreds = Math.floor(num / 100 % 10),
thousands = Math.floor(num % 10000 / 1000);
Run Code Online (Sandbox Code Playgroud)
我只需要:
- 我甚至不知道其余部分是否可行,但如果您有任何提示或至少找到一个,请告诉我!谢谢.
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);
Run Code Online (Sandbox Code Playgroud)
管理到达1亿.