@fixit293/number-to-words
v1.0.0
Published
Convert numbers to words with support for Nigerian Naira and Kobo
Maintainers
Readme
Number to Words (Naira Edition)
Convert numbers to their word equivalents with support for Nigerian Naira and Kobo. Perfect for generating cheques, invoices, and financial documents.
Features
✅ Convert integers to words (0 - 999,999,999,999) ✅ Decimal/fractional support for kobo ✅ Clean, readable output ✅ Lightweight with zero dependencies ✅ TypeScript support ✅ Works in Node.js and browsers
Installation
npm install number-to-words-nairaor
yarn add number-to-words-nairaQuick Start
import { numberToWord } from "number-to-words-naira";
const result = numberToWord(1234.56);
console.log(result);
// {
// naira: "One Thousand, Two Hundred and Thirty-Four",
// kobo: "Five Six"
// }Usage Examples
Basic Numbers
numberToWord(0);
// { naira: "Zero", kobo: "" }
numberToWord(42);
// { naira: "Forty-Two", kobo: "" }
numberToWord(1000);
// { naira: "One Thousand", kobo: "" }With Decimals
numberToWord(50.25);
// { naira: "Fifty", kobo: "Two Five" }
numberToWord(1500000.99);
// { naira: "One Million, Five Hundred Thousand", kobo: "Nine Nine" }Formatting for Financial Documents
const { naira, kobo } = numberToWord(15750.5);
const formatted = `${naira} Naira${kobo ? `, ${kobo} Kobo` : ""} Only`;
console.log(formatted);
// "Fifteen Thousand, Seven Hundred and Fifty Naira, Five Zero Kobo Only"For Cheque Writing
function formatCheque(amount) {
const { naira, kobo } = numberToWord(amount);
if (kobo) {
return `₦${amount.toFixed(2)} - ${naira} Naira and ${kobo} Kobo Only`;
}
return `₦${amount.toFixed(2)} - ${naira} Naira Only`;
}
console.log(formatCheque(5000));
// "₦5000.00 - Five Thousand Naira Only"API Reference
numberToWord(value)
Converts a number to its word representation.
Parameters:
value(number | string): The number to convert. Can include decimals.
Returns:
- Object with two properties:
naira(string): The whole number part in wordskobo(string): The decimal part in words (each digit spoken separately)
Examples:
numberToWord(100); // { naira: "One Hundred", kobo: "" }
numberToWord("250.75"); // { naira: "Two Hundred and Fifty", kobo: "Seven Five" }
numberToWord(NaN); // { naira: "", kobo: "" }Supported Range
- Minimum: 0
- Maximum: 999,999,999,999 (999 Billion)
- Decimals: Up to 2 decimal places (kobo)
Common Use Cases
1. Invoice Generation
const invoiceAmount = 45000.0;
const { naira } = numberToWord(invoiceAmount);
console.log(`Amount in words: ${naira} Naira Only`);2. Receipt Printing
function printReceipt(amount) {
const { naira, kobo } = numberToWord(amount);
return {
amount: `₦${amount.toFixed(2)}`,
amountInWords: kobo ? `${naira} Naira, ${kobo} Kobo` : `${naira} Naira`,
};
}3. Banking Applications
const transferAmount = 1000000;
const confirmation = numberToWord(transferAmount);
console.log(`You are transferring ${confirmation.naira} Naira`);Why Use This Package?
- Nigeria-Specific: Built specifically for Naira and Kobo
- Reliable: Handles edge cases and various number formats
- Simple API: Just one function to learn
- Battle-Tested: Used in production financial applications
- No Dependencies: Lightweight and fast
Browser Support
Works in all modern browsers and Node.js environments:
- Chrome, Firefox, Safari, Edge (latest versions)
- Node.js 12+
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
MIT © [Your Name]
Support
If you find this package useful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 📖 Improving documentation
Related Packages
- number-to-words - General purpose, multiple languages
- written-number - International number conversion
Made with ❤️ for Nigerian developers
