繁体   English   中英

四舍五入至200,如果为200,则为-1

[英]round nearest 200 but -1 if 200

我有一排歌,但从0-200开始显示。进入下一页时,它从201-400开始。下一页从401到600等。

我有自动滚动功能,但是我需要它跳到当前歌曲正在播放的页面,然后滚动到该歌曲? 因此,如果歌曲为:250,则我的起始点不应为201,结束显示应为400。但是,如果歌曲为200,则我的起始则不应为0,结束显示为200。我需要提出一种解决方法到最接近的200是其250 260等,但是如果其200,400,600等则为-1,所以如果其200,-1为199,它将四舍五入为0。

也许有更好的解决方案? 无论如何,下面是我的四舍五入代码--很好!

码:

scrolltopage = destination + 1; //number could be 20,201,288 etc 
startpageQueueScroll = parseInt(Math.floor(scrolltopage / 200) * 200 + 1); //Start displaying contents at
endpageQueueScroll = parseInt(Math.floor(scrolltopage / 200) * 200 + 201); //Stop displaying at 
console.log("Start: " + startpageQueueScroll + " and end page: " + endpageQueueScroll); //Display Output

如何使用模运算符? 样例代码:

    function getNextPages(original){
    const nextDestination = original + 1;
    const nextModulus = nextDestination % 200;
    if(nextModulus == 0){
        return -1;
    }
    const nextMinPage = nextDestination - nextModulus + 1;
    const nextMaxPage = nextMinPage + 200;
    console.log(nextMinPage);
    console.log(nextMaxPage);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM