根据天数查找周期。
问题描述:
我有hours
动态号码,我希望他们能在几周 一轮例如假设我用得到的196小时根据天数查找周期。
我转换这个结果为天:
var daysX = hours/24;
现在,如果daysx
等于或小于7,则应将周的值指定为1,如果daysx
大于7但小于14,则周应为2,依此类推。
hours
将是完全动态的,所以我不能申请如果别的&比较。
有什么办法根据小时动态应用周数?
任何想法,将不胜感激!在此先感谢..
答
您可以将小时除以周长,并使用Math.ceil
进行四舍五入。
function getWeeks(hours) {
return Math.ceil(hours/24/7);
}
console.log(getWeeks(196)); // two weeks
console.log(getWeeks(169)); // two weeks
console.log(getWeeks(168)); // one week
答
let hours = 200;
let result = Math.ceil(hours/(24*7))
console.log(result);
这应该做工精细你
答
你可以这样做:
var hours = 196
var days = hours/24;
var week = Math.floor(days /7);
days = days % 7;
答
您可以通过7
var daysX = Math.round(24 * /* hours as number here *//24)/7
通过由
24
划分小时过去了,以
Math.round()
划分数乘以
24