Number
Number
is a pretentiously-named Elixir library which provides functions to convert numbers into a variety of different formats. Ultimately, it aims to be a partial or complete clone of ActionView::Helpers::NumberHelper from Rails.
Number.Currency.number_to_currency(2034.46)
"$2,034.46"
Installation
Get it from Hex:
defp deps do
[{:number, "~> 0.2.0"}]
end
Then run mix deps.get
to install.
Usage
If you want to import all of the functions provided by Number
, simply use
it in your module:
defmodule MyModule do
use Number
end
More likely, you'll want to import the functions you want from one of Number
's submodules.
defmodule MyModule do
import Number.Currency
end
See the Hex documentation for more information about the modules provided by Number
.