我可以使用tolocalestring()在不舍入的情况下截断数字吗?
我想使用 tolocalestring()
截断 9.95
9.9 。问题是 tolocalestring()
始终将数字四舍五入为 10.0
。
>> (9.95).toLocaleString('en-US', {minimumFractionDigits: 1, maximumFractionDigits: 1})
"10.0"
>> (9.95).toLocaleString('en-US', {minimumFractionDigits: 1, maximumFractionDigits: 1, roundingMode: "trunc"})
"10.0"
我想将其用于DENO,但问题是关于JavaScript API,不仅与Deno有关。我做错了吗?
我在脚本(9.95).toString()中使用了此内容。子弦(0,3)
因为舍入问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在 roundingmode ' ecmascript®2023国际化API规范。我认为没有一种方法可以使用
number.prototype.toleocalestring
,也不使用更高级的intl.numberformat.prototype.format.format
。但是,您可以使用
Math.trunc
:
然后您可以将其转换为字符串,等等。
I see no mention of a
roundingMode
in ECMAScript® 2023 Language Specification nor in ECMAScript® 2023 Internationalization API Specification. I do not believe there is a way to do this withNumber.prototype.toLocaleString
nor with the more advancedIntl.NumberFormat.prototype.format
.You can however use some math with
Math.trunc
:Which you can then convert to a string, etc.