JavaScript:如何将金额小数格式设置为 2 位数字
我尝试使用以下命令将金额字段格式设置为 2 位数字 Amount.toLocaleString() toLocaleString(undefined, {minimumFractionDigits: 2 }),
部分金额值显示正确,但少数不正确 例如 $52.85.00 应显示为 $52.85
I tried to format the Amount field to 2 digits using the
Amount.toLocaleString()
toLocaleString(undefined, { minimumFractionDigits: 2 }),
Some of the Amount values are displayed correctly but few are incorrect
like $52.85.00 should be displayed as $52.85
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Number.prototype.toFixed()
来格式化小数位数。注意:toFixed 方法将返回一个字符串,因此如果您的目标不仅仅是显示,则应该转换回浮点数。有关.toFixed()
方法的更多信息 访问文档You can use
Number.prototype.toFixed()
to format with a number of decimals. Note: The toFixed method will return a string, so you should convert back to an floating number if your goal is not just to display. For more info on.toFixed()
method access document