ordinal property

String get ordinal

Converts int into English ordinal representation

print(1.ordinal);  // 1st
print(22.ordinal); // 22nd
print(143.ordinal);// 143rd
print(0.ordinal);  // 0th
print(12.ordinal); // 12th
print(69.ordinal); // 69th

Implementation

String get ordinal {
  if (this % 100 >= 11 && this % 100 <= 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';
  }
}