【发布时间】:2022-01-06 19:57:28
【问题描述】:
我正在尝试编写将数字四舍五入到最接近的百分之一的代码,但如果它只到十分位,它会添加一个零。
由于某种原因,我的代码显示我的小数点类型为“从不”。有什么解决办法吗?
newCost 是我的小数。成本变量是我的显示器。
let newCost =
Math.round(
(parseFloat(cost.textContent) + parseFloat(this.state.price)) *
1.1 *
100
) / 100;
if (typeof newCost === "float" && typeof newCost * 10 === "int") {
cost.textContent = newCost.toString().concat("0");
} else {
cost.textContent = newCost;
}
【问题讨论】:
-
我不明白你通过阅读你的第一段想要达到什么目的。你能添加一些示例输入和输出吗?