NativeScript:格式化数字打字稿 [英] NativeScript: Formatting number typescript

查看:121
本文介绍了NativeScript:格式化数字打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Nativescript完全陌生,并且对某些基本内容进行谷歌搜索比应做的要难... 我想做的基本上是这样的: 我有电话号码

I am totally new to nativescript and googling for the some basic stuff is harder than it should be... What i want to do is basically this: I have the number

1234567.89

1234567.89

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

in a variable, and i want to show it in a label with the format

"1,234,567.89"

"1,234,567.89"

此外,如果89等于0,则始终显示2个小数.

Also, always show 2 decimals in case that 89 is 0 instead.

非常感谢您的帮助

推荐答案

如果您针对现代浏览器,则可以使用:

If you target to modern browsers you can use:

new Intl.NumberFormat('en-us', {minimumFractionDigits: 2}).format(1234567.89)

(1234567.89).toLocaleString('en-us', {minimumFractionDigits: 2})

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

这篇关于NativeScript:格式化数字打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆