The io_lib:fread function is the easiest method. io_lib:fread can handle strings containing base 2 through 36 numbers into a number, though decimal is the default. If the conversion can't be performed, or if the string does not contain a number, io_lib:fread returns {error} (rather than {ok}. Here are some examples showing the proper format specifiers:
This is only half the solution, however. io_lib:fread works for any kind of number, so technically, you should wrap the call in a call to the is_integer predicate:
Even this function is not perfect. It thinks "77.7" is an integer since it reads the 77 and drops the .7 prior to trying the is_integer predicate. Need to research this a bit more.
Is there a reason why the list_to_integer function is not used for this?
1> Is_String_Int = fun(String) ->
1> case (catchlist_to_integer(String)) of
1> {'EXIT', _} -> false;
1> Integer -> true
1> end
1> end.
#Fun<erl_eval.6.56006484>
2> Is_String_Int("77.7").
false
3> Is_String_Int("77").
true