Answers for "elixir string to integer"

0

cast to int elixir

Check Integer.parse/1 and Float.parse/1.
Posted by: Guest on August-03-2021
0

elixir string to integer

@spec parse(binary(), 2..36) ::
          {integer(), remainder_of_binary :: binary()} | :error

Parses a text representation of an integer.

An optional base to the corresponding integer can be provided. If base is not
given, 10 will be used.

If successful, returns a tuple in the form of {integer, remainder_of_binary}.
Otherwise :error.

Raises an error if base is less than 2 or more than 36.

If you want to convert a string-formatted integer directly to an integer,
String.to_integer/1 or String.to_integer/2 can be used instead.

## Examples

    iex> Integer.parse("34")
    {34, ""}

    iex> Integer.parse("34.5")
    {34, ".5"}

    iex> Integer.parse("three")
    :error

    iex> Integer.parse("34", 10)
    {34, ""}

    iex> Integer.parse("f4", 16)
    {244, ""}

    iex> Integer.parse("Awww++", 36)
    {509216, "++"}

    iex> Integer.parse("fab", 10)
    :error

    iex> Integer.parse("a2", 38)
    ** (ArgumentError) invalid base 38
Posted by: Guest on February-22-2022

Browse Popular Code Answers by Language