exmorph v0.1.0 Exmorph.Cast

Summary

Functions

Returns true or false, depending on if the passed string can be cast to a float

Returns true or false, depending on if the passed string can be cast to an integer

Converts a bitstring to a float. Throws an exception if the value cannot be cast

Converts a bitstring to an integer. Throws an exception if the value cannot be cast

Converts a bitstring to a float or integer. Returns the value in its original form if it cannot be cast

Functions

matches_float?(value)

Returns true or false, depending on if the passed string can be cast to a float.

Examples

iex> Exmorph.Cast.matches_float?(".1")
true

iex> Exmorph.Cast.matches_float?("3.14159265359")
true

iex> Exmorph.Cast.matches_float?("12")
false
matches_integer?(value)

Returns true or false, depending on if the passed string can be cast to an integer.

Examples

iex> Exmorph.Cast.matches_integer?("32")
true

iex> Exmorph.Cast.matches_integer?("3.14159265359")
false
to_float(value)

Converts a bitstring to a float. Throws an exception if the value cannot be cast.

Examples

iex> Exmorph.Cast.to_float(".1")
0.1

iex> Exmorph.Cast.to_float("3.14159265359")
3.14159265359
to_integer(value)

Converts a bitstring to an integer. Throws an exception if the value cannot be cast.

Examples

iex> Exmorph.Cast.to_integer("32")
32
to_numeric(value)

Converts a bitstring to a float or integer. Returns the value in its original form if it cannot be cast.

Examples

iex> Exmorph.Cast.to_numeric(".10")
0.1

iex> Exmorph.Cast.to_numeric("10")
10