[utils] Improve int_or_none and float_or_none (#20403)