sonic-pi

https://github.com/sonic-pi-net/sonic-pi

C++

Code. Music. Live.

ActiveSupport::NumberHelper#number_to_currency

Formats a +number+ into a currency string (e.g., $13.65). You
can customize the format in the +options+ hash.

==== Options

* <tt>:locale</tt> - Sets the locale to be used for formatting
  (defaults to current locale).
* <tt>:precision</tt> - Sets the level of precision (defaults
  to 2).
* <tt>:unit</tt> - Sets the denomination of the currency
  (defaults to "$").
* <tt>:separator</tt> - Sets the separator between the units
  (defaults to ".").
* <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  to ",").
* <tt>:format</tt> - Sets the format for non-negative numbers
  (defaults to "%u%n").  Fields are <tt>%u</tt> for the
  currency, and <tt>%n</tt> for the number.
* <tt>:negative_format</tt> - Sets the format for negative
  numbers (defaults to prepending an hyphen to the formatted
  number given by <tt>:format</tt>).  Accepts the same fields
  than <tt>:format</tt>, except <tt>%n</tt> is here the
  absolute value of the number.

==== Examples

  number_to_currency(1234567890.50)                # => $1,234,567,890.50
  number_to_currency(1234567890.506)               # => $1,234,567,890.51
  number_to_currency(1234567890.506, precision: 3) # => $1,234,567,890.506
  number_to_currency(1234567890.506, locale: :fr)  # => 1 234 567 890,51 €
  number_to_currency('123a456')                    # => $123a456

  number_to_currency(-1234567890.50, negative_format: '(%u%n)')
  # => ($1,234,567,890.50)
  number_to_currency(1234567890.50, unit: '&pound;', separator: ',', delimiter: '')
  # => &pound;1234567890,50
  number_to_currency(1234567890.50, unit: '&pound;', separator: ',', delimiter: '', format: '%n %u')
  # => 1234567890,50 &pound;

Source | Google | Stack overflow

Edit

git clone [email protected]:sonic-pi-net/sonic-pi.git

cd sonic-pi

open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/number_helper.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-ActiveSupport--NumberHelper-number_to_currency-for-pr


# Commit to git

git add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/number_helper.rbgit commit -m "better docs for ActiveSupport::NumberHelper#number_to_currency"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-ActiveSupport--NumberHelper-number_to_currency-for-pr

hub pull-request


# Celebrate!