Learn how to format a number with two decimals in JavaScript.
You can use the toFixed()
method to format a number to only show two decimals. Note that the result is rounded (shows 5.57 instead of 5.56):
If you want to display three decimals, just change the number to 3:
Tip: Learn more about the toFixed() method in our JavaScript Reference.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!