NativeScript:格式化数字打字稿

Ari*_*oli 3 typescript nativescript

我对nativescript完全不熟悉并且谷歌搜索一些基本的东西比它应该更难...我想要做的基本上是这样的:我有这个号码

1234567.89

在变量中,我想在格式的标签中显示它

"1,234,567.89"

此外,如果89为0,则始终显示2位小数.

我在这里先向您的帮助表示感谢

Hol*_*min 13

如果您定位到现代浏览器,您可以使用:

new Intl.NumberFormat('en-us', {minimumFractionDigits: 2}).format(1234567.89)
Run Code Online (Sandbox Code Playgroud)

要么

(1234567.89).toLocaleString('en-us', {minimumFractionDigits: 2})
Run Code Online (Sandbox Code Playgroud)

对于浏览器支持:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat