Type conversions in simple variable types
Every simple variable type supports type conversion by invoking the constructor of the type.
int
Available for uint8
, uint16
, uint32
/uint
, uint64
, int8
, int16
, int32
/int
and int64
. When the conversion to an int fails, an exception is thrown.
Example
string
The string constructor accepts every type except for protos. Objects and structs are converted into JSON, other simple types are just being converted into strings (like with toString
).
Example
float
Available for float32
/float
as well as float64
/double
. When the conversion to a float fails, an exception is thrown.
Example
bool
When the conversion to a bool fails, an exception is thrown.
Example
atom
Under the hood, the conversion to an atom will use toString
. The conversion to an atom will only fail if one tries to convert a non-simple datatype.
Example
pid
The only datatype that can be converted to a pid is an int. That is because the value of a pid is an int.
Last updated