使用React native EXPO时如何将数字格式化为货币?
问题描述:
我该如何获取像10000
这样的数字并将其输出为$10,000.00
?
how do I take a number like 10000
and have it output as $10,000.00
?
我什至遇到了String.format(...)
的问题,并出现了Not a function
错误.
I even had a problem with String.format(...)
with a Not a function
error.
我关注了无数文章,所有文章都不完整,没有任何内容.
I followed numerous articles, all incomplete and none working.
我不需要完全的国际化,只需要格式化数字的能力
I don't need full internationalization, just the ability to format a number
答
您可以使用此库反应编号格式.具有这些功能
You can use this library react-number-format. It has these features
- 前缀,后缀和千位分隔符.
- 自定义格式模式.
- 掩盖.
- 自定义格式处理程序.
- 在输入中格式化数字或 格式为简单文本
- Prefix, suffix and thousand separator.
- Custom format pattern.
- Masking.
- Custom formatting handler.
- Format number in an input or format as a simple text
样品用量
<NumberFormat value={2456981} displayType={'text'} thousandSeparator={true} prefix={'$'} />
输出:$ 2,456,981
Output : $2,456,981