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

Returns

  • a Unit.t of the unit type to_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"}}