更新时间:2023-12-03 16:27:22
toFixed 是实现您要查找的内容的另一种方法,并且始终显示小数位,无论它们是否为0.
toFixed is another way to achieve what you are looking for, and will always show the decimal places regardless if they are 0 or not.
<form onsubmit="return false" oninput="o.value = (a.valueAsNumber + b.valueAsNumber).toFixed(2)"<br>
<input name="a" id="a" type="number" step="any"> +<br>
<input name="b" id="b" type="number" step="any"> =<br>
<output name="o" for="a b"></output><br>
</form>
Live Demo