numWithOrdinal method
Adds ordinal to any number
Implementation
String numWithOrdinal(int number) {
String result = '';
if (number == 1) {
result = 'first';
} else if (number == 2) {
result = 'second';
} else if (number == 3) {
result = 'third';
} else {
if (number.toString().length > 1) {
// number is greater than 9
if (number == 11) {
result = 'Eleven';
} else if (number == 12) {
result = 'Twelve';
} else {
String myOrdinal = 'th';
String lastDigitToString =
number.toString().substring(number.toString().length - 1);
if (lastDigitToString == '1') {
myOrdinal = 'first';
} else if (lastDigitToString == '2') {
myOrdinal = 'second';
} else if (lastDigitToString == '3') {
myOrdinal = 'Third';
} else if (lastDigitToString == '8') {
myOrdinal = 'h';
}
// final _yearLastWord= numToWord(number).split(' ').last;
// final _yearWithoutLastWord= numToWord(number).replaceAll(_yearLastWord, '');
result = numToWord(number)+ myOrdinal;
}
} else if (number == 8) {
result = 'eighth';
} else {
result = numToWord(number) + 'th';
}
}
return result;
}