Units
Arithmetic for converting SI unit prefixes.
Examples
iex> Units.from(1, :mega, :byte) |> Units.to_int(:kilo, :byte)
1024
iex> Units.from(1, :mega, :byte) |> Units.to_int(:byte)
1048576
iex> Units.from(2, :kilo, :meter) |> Units.to_int(:centi, :meter)
200000
The following units of measurement are recognized:
:meter
:pico
, :nano
, :micro
, :milli
, :centi
, :deci
, :deca
, :hecto
, :kilo
, :mega
, :giga
:byte
:kilo
, :mega
, :giga
, :tera
, :peta
Summary
Functions
Returns the amount as a float
Creates new unit and uses a single unit of measurement
Creates new unit
Returns the amount as an integer
Converts a unit to another and returns a unit. Uses a single unit of measurement
Converts a unit to another and returns a unit
Converts a unit to another and returns a float. Short for to/2 |> float/1
Converts a unit to another and returns a float. Short for to/3 |> float/1
Converts a unit to another and returns an integer. Short for to/2 |> int/1
Converts a unit to another and returns an integer. Short for to/3 |> int/1
Functions
Creates new unit and uses a single unit of measurement.
Example:
iex> Units.from(1, :meter)
%{amount: 1, quantity: :meter, unit: :one}
Creates new unit.
Example:
iex> Units.from(2, :kilo, :byte)
%{amount: 2, quantity: :byte, unit: :kilo}
Converts a unit to another and returns a unit. Uses a single unit of measurement.
Example:
iex> Units.from(1, :kilo, :meter) |> Units.to(:meter)
%{amount: 1000, quantity: :meter, unit: :one}
Converts a unit to another and returns a unit.
Example:
iex> Units.from(100, :deci, :meter) |> Units.to(:centi, :meter)
%{amount: 1000, quantity: :meter, unit: :centi}
Converts a unit to another and returns a float. Short for to/2 |> float/1
Converts a unit to another and returns a float. Short for to/3 |> float/1