使用React native EXPO时如何将数字格式化为货币? [英] how do you format a number to currency when using React native EXPO?

查看:151
本文介绍了使用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

  1. 前缀,后缀和千位分隔符.
  2. 自定义格式模式.
  3. 掩盖.
  4. 自定义格式处理程序.
  5. 在输入中格式化数字或 格式为简单文本
  1. Prefix, suffix and thousand separator.
  2. Custom format pattern.
  3. Masking.
  4. Custom formatting handler.
  5. 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

这篇关于使用React native EXPO时如何将数字格式化为货币?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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