rn-decimal-input
v1.0.6
Published
**React Native Custom Input** for consistent decimal formatting โ adds `,` (comma) even when entering whole numbers! Now with optional currency symbols! ๐ฏ
Maintainers
Readme
๐งฎ rn-decimal-input
React Native Custom Input for consistent decimal formatting โ adds , (comma) even when entering whole numbers! Now with optional currency symbols! ๐ฏ
โจ Features
- โ Comma formatting for all numbers (even whole numbers!)
- ๐ฒ Optional currency symbol support ($, โฌ, ยฃ, etc.)
- ๐ง Automatically handles input formatting
- ๐จ Fully styleable with
TextInputprops - ๐ช TypeScript support
- ๐ฆ Lightweight and fast
๐ฆ Installation
npm install rn-decimal-inputor with Yarn:
yarn add rn-decimal-input๐งฑ Usage
Basic Usage
import React from 'react';
import { View, StyleSheet } from 'react-native';
import FormattedDecimalInput from 'rn-decimal-input';
export default function App() {
const [value, setValue] = React.useState('');
return (
<View style={styles.container}>
<FormattedDecimalInput
value={value}
onChangeText={setValue}
placeholder="Enter number"
style={styles.input}
keyboardType="numeric"
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
marginTop: 100,
padding: 16,
},
input: {
borderWidth: 1,
borderColor: '#ccc',
padding: 12,
borderRadius: 8,
fontSize: 18,
},
});With Currency Symbol
import React from 'react';
import { View, StyleSheet } from 'react-native';
import FormattedDecimalInput from 'rn-decimal-input';
export default function App() {
const [value, setValue] = React.useState('');
return (
<View style={styles.container}>
<FormattedDecimalInput
value={value}
onChangeText={setValue}
placeholder="Enter amount"
style={styles.input}
keyboardType="numeric"
currency="$" // Add currency symbol prefix
/>
</View>
);
}โ๏ธ Props
This component accepts all native TextInput props ๐ฅ. Below are some key ones:
| Prop | Type | Description | Required |
|----------------|----------|---------------------------------------------|----------|
| value | string | The current input value | Yes |
| onChangeText | function | Callback when text changes (formatted) | Yes |
| style | object | Styles to apply to the input | No |
| currency | string | Currency symbol to display before the value | No |
| ...TextInputProps | any | All other native TextInput props supported | No |
๐งช Output Examples
| Input | Displayed (No Currency) | Displayed (With currency="$") |
|-------|-------------------------|--------------------------------|
| 1 | 1 | $1 |
| 100 | 100 | $100 |
| 1000| 1,000 | $1,000 |
| 1000000.50 | 1,000,000.50 | $1,000,000.50 |
๐ก Why Use This?
Say goodbye to messy formatting and inconsistent user input! This is perfect for:
- ๐ฐ Price fields
- ๐ Financial data
- ๐ฒ Currency inputs
- ๐ข Any decimal number entry
๐งโ๐ป Author
Made with โค๏ธ by @meetmuaz
๐ License
MIT License ยฉ 2025
Check LICENSE for details.
๐ข Contributions Welcome!
Have ideas, suggestions, or improvements? Feel free to open a PR or an issue! ๐
Happy Coding! ๐
