use for instead of while loop in str_to_num