doubletosinhala 0.0.1
doubletosinhala: ^0.0.1 copied to clipboard
A Flutter and Dart library to convert double and numeric values into Sinhala words, supporting currency format, decimals, and large numbers.
doubletosinhala #
A comprehensive Flutter & Dart package for converting double, int, and numeric String values into natural, grammatically accurate Sinhala words (සිංහල අක්ෂර).
Perfect for invoicing, banking, e-commerce, POS systems, receipts, and localized Sri Lankan applications.
✨ Features #
- 🇱🇰 Accurate Sinhala Grammar: Correct compound prefixes for tens (විසි, තිස්, හතලිස්, පනස්, හැට, හැත්තෑ, අසූ, අනූ), hundreds, and thousands.
- 💵 Sri Lankan Currency Format (LKR): Converts amounts directly to standard currency phrases (e.g.
1250.50→"රුපියල් එක්දාස් දෙසීය පනහයි ශත පනහයි"or"රුපියල් එක්දාස් දෙසීය පනහයි ශත පනහයි පමණි"). - 🔢 Decimal Reading Mode: Pronounce numbers digit-by-digit after the decimal point (e.g.
12.50→"දොළහයි දශම පහ බින්දුව"). - ⚡ Intuitive Extensions: Extension methods directly on
double,int,num, andString(123.45.toSinhalaWords()). - 📈 Large Number Support: Handles values up to billions (සීය, දාහ, ලක්ෂය, දස ලක්ෂය, කෝටි, බිලියන).
- 🚀 Zero Dependencies: Pure Dart logic, ultra-lightweight, and runs everywhere (Flutter iOS, Android, Web, macOS, Windows, Linux, and pure Dart servers).
📦 Installation #
Add doubletosinhala to your pubspec.yaml:
flutter pub add doubletosinhala
Or for pure Dart projects:
dart pub add doubletosinhala
Then import it into your code:
import 'package:doubletosinhala/doubletosinhala.dart';
🚀 Quick Usage #
1. Basic Double to Sinhala Words #
import 'package:doubletosinhala/doubletosinhala.dart';
void main() {
// Convert double to Sinhala words
print(doubleToSinhalaWords(123.45));
// Output: එකසීය විසි තුන හා සත හතලිස් පහ
print(doubleToSinhalaWords(100.00));
// Output: එක සීය
print(doubleToSinhalaWords(55.25));
// Output: පනස් පහ හා සත විසි පහ
}
2. Sri Lankan Currency Format (රුපියල් සහ ශත) #
// Standard currency phrase
print(doubleToSinhalaCurrency(1250.50));
// Output: රුපියල් එක්දාස් දෙසීය පනහයි ශත පනහයි
// Append "පමණි" (Only) for cheques and receipts
print(doubleToSinhalaCurrency(1250.50, appendOnly: true));
// Output: රුපියල් එක්දාස් දෙසීය පනහයි ශත පනහයි පමණි
// Without the "රුපියල්" prefix
print(doubleToSinhalaCurrency(100.0, includeRupeesPrefix: false));
// Output: එකසීයයි
// Cents only
print(doubleToSinhalaCurrency(0.50));
// Output: ශත පනහයි
3. Decimal Reading Mode #
// Pronounces decimals digit-by-digit
print(doubleToSinhalaWords(12.50, format: SinhalaFormat.decimal));
// Output: දොළහයි දශම පහ බින්දුව
4. Convenient Extension Methods #
// Double extension
print(123.45.toSinhalaWords());
// Output: එකසීය විසි තුන හා සත හතලිස් පහ
print(1500.00.toSinhalaCurrency(appendOnly: true));
// Output: රුපියල් එක්දාස් පන්සීයයි පමණි
// Integer extension
print(22.toSinhalaWords());
// Output: විසි දෙක
print(500.toSinhalaCurrency());
// Output: රුපියල් පන්සීයයි
// Numeric string extension
print('999.99'.toSinhalaWords());
// Output: නවය සීය අනූ නවය හා සත අනූ නවය
5. Large Numbers & Integer Conversions #
print(convertIntegerToSinhala(1234));
// Output: එක්දාස් දෙසීය තිස් හතර
print(convertIntegerToSinhala(100000));
// Output: ලක්ෂය
print(convertIntegerToSinhala(1000000));
// Output: දස ලක්ෂය
print(convertIntegerToSinhala(10000000));
// Output: කෝටි
print(convertIntegerToSinhala(1000000000));
// Output: බිලියන
📖 API Reference #
| Function / Extension | Description | Example Input | Example Output |
|---|---|---|---|
doubleToSinhalaWords(double, {precision, format}) |
Converts a double with decimal precision | 123.45 |
එකසීය විසි තුන හා සත හතලිස් පහ |
doubleToSinhalaCurrency(double, {precision, appendOnly, includeRupeesPrefix}) |
Formats into Sri Lankan Rupees & Cents | 1250.50 |
රුපියල් එක්දාස් දෙසීය පනහයි ශත පනහයි |
convertIntegerToSinhala(int, {prefixOne}) |
Converts integers up to 999,999,999,999 | 1234 |
එක්දාස් දෙසීය තිස් හතර |
stringToSinhalaWords(String, {precision, format}) |
Parses numeric string and converts | '50.25' |
පනහ හා සත විසි පහ |
toSinhalaWords(dynamic, {precision, format}) |
Universal converter for int, double, String |
123 |
එකසීය විසි තුන |
double.toSinhalaWords() |
Extension on double |
55.25.toSinhalaWords() |
පනස් පහ හා සත විසි පහ |
double.toSinhalaCurrency() |
Extension for currency on double |
100.0.toSinhalaCurrency() |
රුපියල් එකසීයයි |
int.toSinhalaWords() |
Extension on int |
35.toSinhalaWords() |
තිස් පහ |
String.toSinhalaWords() |
Extension on String |
'1000'.toSinhalaWords() |
එක දාහ |
🎯 Supported Scales #
| Scale | Sinhala Word | Example | Sinhala Output |
|---|---|---|---|
| 100 | සීය / එකසීය | 100 |
සීය |
| 1,000 | දාහ / එක්දාස් | 1,234 |
එක්දාස් දෙසීය තිස් හතර |
| 100,000 | ලක්ෂය | 100,000 |
ලක්ෂය |
| 1,000,000 | දස ලක්ෂය | 1,000,000 |
දස ලක්ෂය |
| 10,000,000 | කෝටි | 10,000,000 |
කෝටි |
| 1,000,000,000 | බිලියන | 1,000,000,000 |
බිලියන |
📱 Interactive Example #
An interactive Flutter example application is included in the example/ directory. You can run it to test conversions in real-time with UI controls and copy-to-clipboard functionality.
cd example
flutter run
🤝 Contributing #
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
📄 License #
This project is licensed under the MIT License - see the LICENSE file for details.