Try to parse to int, fallback to def
def
int toInt({int def = 0}) { if (this == null) return def; return int.tryParse(toString()) ?? def; }