计算进度比例(0 ~ 1)
异常:total 为 0、NaN、Infinity 时抛出 Error。 value 为 NaN / Infinity 时静默返回 0(由 toNumber 链兜底)。 注意这种不对称处理——分母有严格校验,分子宽容静默。
total
Error
value
toNumber
— 当前值(分子)
— 总值(分母)
进度比例,四舍五入到小数点后 2 位,钳制在 [0, 1]
当 total === 0 或 !isNumber(total) 时
total === 0
!isNumber(total)
calcProgress(50, 100); // 0.5calcProgress(0, 100); // 0calcProgress(150, 100); // 1(被钳制)calcProgress(50, 0); // 抛 Error Copy
calcProgress(50, 100); // 0.5calcProgress(0, 100); // 0calcProgress(150, 100); // 1(被钳制)calcProgress(50, 0); // 抛 Error
计算进度比例(0 ~ 1)
异常:
total为 0、NaN、Infinity 时抛出Error。value为 NaN / Infinity 时静默返回 0(由toNumber链兜底)。 注意这种不对称处理——分母有严格校验,分子宽容静默。