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

查看:13
本文介绍了使用 React 本机 Expo 时如何将数字格式化为货币?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取像 10000 这样的数字并将其输出为 $10,000.00?我什至遇到了 String.format(...) 的问题,出现 Not a function 错误.

How do I take a number like 10000 and have it output as $10,000.00? 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. 在输入中格式化数字或格式为简单的文本

示例用法

<NumberFormat value={2456981} displayType={'text'} thousandSeparator={true} prefix={'$'} />

产出:2,456,981 美元

Output : $2,456,981

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

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