我怎样才能将输出四舍五入为整数?
How would i be able to round the outputs to an integer?
我需要让这些输出产生一个整数而不是小数
{
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);
}
您可以使用 Math.round()
:
The Math.round()
function returns the value of a number rounded to the nearest integer.
outputs[0].textContent = Math.round(value / 0.7);
.....
.....
{
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);
}
我需要让这些输出产生一个整数而不是小数
{
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);
}
您可以使用 Math.round()
:
The
Math.round()
function returns the value of a number rounded to the nearest integer.
outputs[0].textContent = Math.round(value / 0.7);
.....
.....
{
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);
}