numberToWords static method
Convert number to words (Indian format)
number - The number to convert
Returns number in words
Implementation
static String numberToWords(int number) {
if (number == 0) return 'Zero';
final ones = ['', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
final teens = ['Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'];
final tens = ['', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'];
final thousands = ['', 'Thousand', 'Lakh', 'Crore'];
String result = '';
int num = number;
int thousandIndex = 0;
while (num > 0) {
int group = num % 1000;
if (group != 0) {
String groupWords = _convertGroup(group, ones, teens, tens);
if (thousandIndex > 0) {
groupWords += ' ${thousands[thousandIndex]}';
}
result = groupWords + (result.isEmpty ? '' : ' $result');
}
num ~/= 1000;
thousandIndex++;
}
return result;
}