Cldr Units v1.2.2 Cldr.Unit.Conversion View Source

Unit conversion functions for the units defined in Cldr.

Link to this section Summary

Functions

Convert one unit into another unit of the same unit type (length, volume, mass, …)

Link to this section Functions

Convert one unit into another unit of the same unit type (length, volume, mass, …)

Options

Returns

  • a Unit.t of the unit type to_unit or

  • {:error, {exception, message}}

Examples

iex> Cldr.Unit.convert Cldr.Unit.new!(:celsius, 0), :fahrenheit
#Unit<:fahrenheit, 32.0>

iex> Cldr.Unit.convert Cldr.Unit.new!(:fahrenheit, 32), :celsius
#Unit<:celsius, 0.0>

iex> Cldr.Unit.convert Cldr.Unit.new!(:mile, 1), :foot
#Unit<:foot, 5279.945925937846>

iex> Cldr.Unit.convert Cldr.Unit.new!(:mile, 1), :gallon
{:error, {Cldr.Unit.IncompatibleUnitError,
          "Operations can only be performed between units of the same type. Received :mile and :gallon"}}