humanNum property

String get humanNum

This extension provides a method get humanNum to get the ordinal form of an integer.

Example:

int num = 5;
print(num.humanNum);  // Output: Fifth

It works for numbers from 1 to 10. For any number outside this range, the method will simply return the original number.

Note: Make sure to import this extension where you want to use it.

Implementation

String get humanNum {
  Map nums = {
    1: "	First",
    2: "	Second",
    3: "	Third",
    4: "	Fourth",
    5: "	Fifth",
    6: "	Sixth",
    7: "	Seventh",
    8: "	Eighth",
    9: "	Ninth",
    10: "	Tenth",
  };

  return '${nums[this] ?? this}';
}