About Me
I am shamim hasnain (shadid), a Flutter & React developer with a passion for creating reusable UI components. I have created this package to help you convert numbers to words.
hasnain_ui_number_to_word
A Flutter package that converts numeric values into their word representations. This package provides an easy-to-use solution for converting numbers into words, supporting values from zero up to trillions.
Features
- Convert numbers to words (0 to 999,999,999,999,999)
- Support for single digits, teens, tens, hundreds, thousands, millions, billions, and trillions
- Clean and readable output format
- Handles zero and positive integers
- Throws ArgumentError for negative numbers
Installation
Add this to your package's pubspec.yaml
file:
dependencies:
hasnain_ui_number_to_word: ^1.0.1
Then run:
flutter pub get
Usage
import 'package:hasnain_ui_number_to_word/hasnain_ui_number_to_word.dart';
void main() {
// Basic usage
print(NumberToWord.numberToWord(0)); // Output: Zero
print(NumberToWord.numberToWord(42)); // Output: Forty Two
print(NumberToWord.numberToWord(1000)); // Output: One Thousand
// Larger numbers
print(NumberToWord.numberToWord(1000000)); // Output: One Million
print(NumberToWord.numberToWord(1000000000)); // Output: One Billion
print(NumberToWord.numberToWord(1000000000000)); // Output: One Trillion
}
Screenshots
Example
final String result = NumberToWord.numberToWord(1234);
print(result); // Output: One Thousand Two Hundred Thirty Four
Error Handling
The package throws an ArgumentError
when attempting to convert negative numbers:
try {
NumberToWord.numberToWord(-1);
} catch (e) {
print(e); // Output: ArgumentError: Negative numbers are not supported.
}
Limitations
- Only supports integers
- Does not support negative numbers
- Maximum supported number is 999,999,999,999,999 (999 trillion)
License
This project is licensed under the MIT License - see the LICENSE file for details.