Cldr.Unit.Conversion.convert
You're seeing just the function
convert
, go back to Cldr.Unit.Conversion module for more information.
Specs
convert(Cldr.Unit.t(), Cldr.Unit.unit()) :: {:ok, Cldr.Unit.t()} | {:error, {module(), String.t()}}
Convert one unit into another unit of the same unit type (length, volume, mass, ...)
Arguments
unit
is any unit returned byCldr.Unit.new/2
to_unit
is any unit name returned byCldr.Unit.known_units/0
Returns
a
Unit.t
of the unit typeto_unit
or{:error, {exception, message}}
Examples
iex> Cldr.Unit.convert Cldr.Unit.new!(:mile, 1), :foot
{:ok, Cldr.Unit.new!(:foot, 5280)}
iex> Cldr.Unit.convert Cldr.Unit.new!(:mile, 1), :gallon
{:error, {Cldr.Unit.IncompatibleUnitsError,
"Operations can only be performed between units with the same base unit. Received :mile and :gallon"}}