计算百分比的剩余百分比

i2byvkas  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(297)

我正在进行几次下载,我加载第一个模块,百分比固定为70%,然后加载其他几个模块,在下载第一个模块后,我知道模块的长度,因此我尝试填充30%以完成100%的进度。

export default class ModuleLoader {
  private percent;
  private first_module_loaded;

  constructor() {
    this.percent = 0;
    this.first_module_loaded = false;
    this.loadFirstModule();
  }

  public updatePercentage(percent) {
    percent = Math.trunc(percent);

    if (this.first_module_loaded) {
      percent = Math.trunc((((percent / 100) * 0.3) * 100));; // here is
      this.percent += percent;
    } else if (!this.first_module_loaded && percent >= 70) this.percent = 70;
    else this.percent += percent;
  }

  public loadFirstModule() {
    //...load the first module
    //this.updatePercentage((bytesLoaded / bytesTotal) * 100)

    //after complete the percentage is fixed to 70%, and load other modules with the modules length retrieved from the first module
    this.first_module_loaded = true;

    this.loadOthersModules(modules_length);
  }

  public loadOthersModules(modules_length) {
    //...load others modules
    //this.updatePercentage(((bytesLoaded / bytesTotal) * 100) / modules_length)
  }
}

我试过了 Math.trunc((((percent / 100) * 0.3) * 100)) 但最后百分比总是大于100

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题