【问题标题】:How would i be able to round the outputs to an integer?我如何能够将输出四舍五入为整数?
【发布时间】:2021-08-19 12:32:40
【问题描述】:

我需要让这些输出产生一个整数而不是小数

 {
    outputs[0].textContent = value / 0.7;
    outputs[1].textContent = value * 1;
    outputs[2].textContent = value / 0.7 - (value / 0.7 /  100*40);
    outputs[3].textContent = value * 1;
    outputs[4].textContent = value / 0.7 - (value / 0.7 /  100*20);
    outputs[5].textContent = value / 0.7 - (value / 0.7 /  100*10);
  }

【问题讨论】:

标签: javascript rounding calculator


【解决方案1】:

你可以使用Math.round():

Math.round() 函数返回四舍五入到最接近整数的数值。

outputs[0].textContent = Math.round(value / 0.7);
.....
.....

【讨论】:

    【解决方案2】:
     {
      outputs[0].textContent = Math.round(value);
      outputs[1].textContent = Math.round(value);
      outputs[2].textContent = Math.round(value);
      outputs[3].textContent = Math.round(value);
      outputs[4].textContent = Math.round(value);
      outputs[5].textContent = Math.round(value);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-31
      • 2015-12-05
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 2014-08-26
      • 2015-01-26
      相关资源
      最近更新 更多