Money.to_string

You're seeing just the function to_string, go back to Money module for more information.
Link to this function

to_string(money, options \\ [])

View Source

Specs

to_string(t(), Keyword.t() | Cldr.Number.Format.Options.t()) ::
  {:ok, String.t()} | {:error, {atom(), String.t()}}

Returns a formatted string representation of a Money{}.

Formatting is performed according to the rules defined by CLDR. See Cldr.Number.to_string/2 for formatting options. The default is to format as a currency which applies the appropriate rounding and fractional digits for the currency.

Arguments

  • money is any valid Money.t type returned by Money.new/2

  • options is a keyword list of options or a %Cldr.Number.Format.Options{} struct

Returns

  • {:ok, string} or

  • {:error, reason}

Options

  • :backend is any CLDR backend module. The default is Money.default_backend().

  • Any other options are passed to Cldr.Number.to_string/3

Examples

iex> Money.to_string Money.new(:USD, 1234)
{:ok, "$1,234.00"}

iex> Money.to_string Money.new(:JPY, 1234)
{:ok, "¥1,234"}

iex> Money.to_string Money.new(:THB, 1234)
{:ok, "THB 1,234.00"}

iex> Money.to_string Money.new(:THB, 1234, fractional_digits: 4)
{:ok, "THB 1,234.0000"}

iex> Money.to_string Money.new(:USD, 1234), format: :long
{:ok, "1,234 US dollars"}