A lightweight international currency formatter for React Native & Expo (iOS and Android).
The npm package "react-native-format-currency" is an essential tool for developers working with financial applications in React Native and Expo environments. This lightweight international currency formatter seamlessly integrates with both iOS and Android platforms, providing a robust solution for presenting currency in a user-friendly format. The primary purpose of this module is to help developers quickly implement currency formatting functionality without bogging down their applications with heavy libraries. This not only improves the efficiency of development but also enhances the performance of the app, ensuring that end-users experience smooth and responsive interactions.
To integrate "react-native, format-currency" into your project, simply run the npm install react-native-format-currency command in your project’s terminal. This easy installation process adds the formatter to your project, enabling you to use its features immediately. With this package, developers can format currency values according to different international standards, making applications accessible and intuitive for a global audience. The formatter supports various customization options, allowing developers to tailor the appearance of the currency to fit the specific design and layout of their applications.
One of the significant benefits of using "react-native-format-currency" is its compatibility with the latest versions of React Native and Expo. This ensures that developers are using up-to-date tools that comply with current mobile development standards. Additionally, the package's efficient performance means that it doesn't add unnecessary load to the application, a critical factor when dealing with mobile applications where performance and speed are paramount. The "react-native-format-currency" package continues to be well-maintained, with regular updates that keep it relevant and functional amidst the ever-evolving tech landscape.
A lightweight international currency formatter for React Native & Expo (iOS and Android)...
Read moreCore dependencies of this npm package and its dev dependencies.
undefined@types/node, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, chai, eslint, eslint-config-airbnb, eslint-config-airbnb-typescript, eslint-config-prettier, eslint-plugin-import, eslint-plugin-jsx-a11y, eslint-plugin-prettier, eslint-plugin-react, eslint-plugin-react-hooks, eslint-plugin-react-native, mocha, prettier, typescript
A README file for the react-native-format-currency code repository. View Code
A lightweight international currency formatter for React Native & Expo (iOS and Android). Check out the example app for a working demo.
$ yarn add react-native-format-currency
or
$ npm install react-native-format-currency
Import library with
import { formatCurrency, getSupportedCurrencies } from "react-native-format-currency";
formatCurrency({ amount: _number_, code: _string_})
formatCurrency({ amount: 1234.56, code: "ARS" })
Formats a currency amount to specified currency code:
const [valueFormattedWithSymbol, valueFormattedWithoutSymbol, symbol] = formatCurrency({ amount: 1234.56, code: "ARS" })
Props
Prop | Type | Default | Note |
---|---|---|---|
amount |
Number |
null | currency amount |
code |
String |
null | 3-letter ISO 4217 Currency Code |
Returns:
Array containing formatted currency string, formatted currency (without symbol), and currency symbol
["$ 1.234,56", "1.234,56", "$"]
getSupportedCurrencies()
getSupportedCurrencies()
Returns an array of currencies:
[
{ code: "ARS", name: "Argentina Peso" },
{ code: "AUD", name: "Australia Dollar" },
{ code: "BGN", name: "Bulgaria Lev" },
{ code: "BRL", name: "Brazil Real" },
{ code: "CAD", name: "Canada Dollar" },
{ code: "CHF", name: "Switzerland Franc" },
{ code: "CLP", name: "Chile Peso" },
{ code: "CNY", name: "China Yuan Renminbi" },
{ code: "COP", name: "Colombia Peso" },
{ code: "CZK", name: "Czech Republic Koruna" },
{ code: "DKK", name: "Denmark Krone" },
{ code: "EUR", name: "Euro Member Countries" },
{ code: "GBP", name: "United Kingdom Pound" },
{ code: "HKD", name: "Hong Kong Dollar" },
...
]
Check out the example app for a working demo.
import { StatusBar } from "expo-status-bar";
import React, { useState } from "react";
import {
FlatList,
SafeAreaView,
StyleSheet,
Text,
TextInput,
View,
} from "react-native";
import {
formatCurrency,
getSupportedCurrencies,
} from "react-native-format-currency";
export default function App() {
const [inputValue, setInputValue] = useState("1234.56");
// get all of the supported currency codes
const currencyCodes = getSupportedCurrencies();
// loop through each currency code and show formatted value
const renderItem = ({ item }) => {
const [valueFormattedWithSymbol, valueFormattedWithoutSymbol, symbol] =
formatCurrency({ amount: Number(inputValue), code: item.code });
return (
<View style={styles.currencyRow}>
<Text style={styles.currencyRowText}>
{item.code} {symbol}
</Text>
<Text style={styles.currencyRowText}>{item.name}</Text>
<Text style={styles.currencyRowText}>{valueFormattedWithSymbol}</Text>
</View>
);
};
return (
<SafeAreaView style={styles.container}>
<View style={styles.inputContainer}>
<TextInput
style={styles.input}
textAlign="center"
value={inputValue}
onChangeText={(value) => setInputValue(value)}
keyboardType="decimal-pad"
/>
</View>
<FlatList
style={styles.scrollView}
data={currencyCodes}
renderItem={renderItem}
keyExtractor={(code) => code.code}
/>
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "flex-start",
},
inputContainer: {
flex: 1,
alignSelf: "stretch",
marginTop: 10,
marginBottom: 15,
},
input: {
backgroundColor: "#eee",
height: 38,
fontSize: 30,
fontWeight: "bold",
},
scrollView: {
width: "100%",
paddingHorizontal: 5,
marginTop: 40,
marginBottom: 40,
},
currencyRow: {
flex: 1,
flexDirection: "row",
justifyContent: "space-between",
},
currencyRowText: {
alignContent: "flex-start",
color: "#000",
fontSize: 16,
},
});
yarn build
yarn test
Feel free to submit a PR if you'd like to help!