9n
1~9 9X1
10~18 9X2
19~17 9X3
18~36 9X4
假如有个数字是21,怎样通过js的方法得到他是那个倍数(n)的区间的呢?
Math.floor(n / 9) * 9 < n < (Math.floor(n / 9) + 1) * 9
换句话说,这个数字是在Math.floor(n / 9)
和(Math.floor(n / 9) + 1)
的9倍之间
var num=21;//需要判断的数
var fold;//区间
if(num/9==0){
fold=parseInt(num/9)
console.log(fold)
}else{
fold=parseInt(num/9)+1
console.log(fold)
}
除以9取余数,余数大于0,倍数就是商加1