lastDigits method

int lastDigits(
  1. int n
)

Retrieves the last n digits of the integer.

Example:

print(123456.lastDigits(3)); // 456

Implementation

int lastDigits(int n) {
  if (isNull()) return 0;
  int charCount = n;
  if (toString().trim().length < n) {
    charCount = toString().trim().length;
  }
  return (toString().trim().substring(toString().trim().length - charCount))
          .toInt() ??
      0;
}