toOrdinal method
Converts the integer to its ordinal representation (e.g., 1st, 2nd).
Implementation
String toOrdinal() {
if (this < 0) throw Exception('Invalid Number');
if (this >= 11 && this <= 13) {
return '${this}th';
}
switch (this % 10) {
case 1:
return '$this st';
case 2:
return '$this nd';
case 3:
return '$this rd';
default:
return '$this th';
}
}