Javascript 获取带模数的数字的位置值?
我需要获得用户提交的随机数的位置值。 这个数字可以是0-1000000000000(0到1 万亿美元)Javascript 获取带模数的数字的位置值?,javascript,math,division,modulus,Javascript,Math,Division,Modulus,我需要获得用户提交的随机数的位置值。 这个数字可以是0-1000000000000(0到1 万亿美元) 我认为这可以通过使用JavaScript模数% 操作人员问题是,我真的不知道如何使用它,我也不知道 理解它 这是最新版本。 (我只知道10%3返回1,因为3*3=9和10-9=1) 我算出了一、十、百、千: var ones = Math.floor(num % 10), tens = Math.floor(num / 10 % 10), hundreds = Math.fl
%
操作人员问题是,我真的不知道如何使用它,我也不知道 理解它
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);
我只需要:
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);
设法达到1亿。var scaleStepWidth=0;
var scaleStepWidth = 0;
var number = Math.ceil(1052220420.32);
var placeValue = 1;
for(i=0;i<(number.toString().length-1);i++){
placeValue *= 10;
}
scaleStepWidth = eval(number.toString()[0])*placeValue;
var编号=数学ceil(1052220420.32);
var placeValue=1;
对于(i=0;i)问题,我真的不知道如何使用它,也不理解它
?你需要位置值做什么?我正在做一个数字到单词的翻译。@Bergi--这很有帮助。谢谢你!@CptRobby--我感谢你的帮助。如果你看我下面的答案,你会发现我找到了!是的,这就是我正在做的,但用西班牙语说:)我无法编辑,但我相信第四行应该是:数千=Math.floor(num/1000%10)