Module CurrencyInWords
In: lib/currency-in-words.rb

encoding: utf-8

Methods

Classes and Modules

Class CurrencyInWords::EnTexterizer
Class CurrencyInWords::FrTexterizer
Class CurrencyInWords::Texterizer

Constants

DEFAULT_CURRENCY_IN_WORDS_VALUES = {:currencies=>{:default=>{:unit=>{:one=>'dollar',:many=>'dollars'}, :decimal=>{:one=>'cent',:many=>'cents'}}}, :connector=>', ',:format=>'%n',:negative_format=>'minus %n'}

Public Instance methods

Formats a number into a currency string (e.g., ‘one hundred dollars’). You can customize the format in the options hash.

Options for all locales

  • :locale - Sets the locale to be used for formatting (defaults to current locale).
  • :currency - Sets the denomination of the currency (defaults to :default currency for the locale or "dollar" if not set).
  • :connector - Sets the connector between integer part and decimal part of the currency (defaults to ", ").
  • :format - Sets the format for non-negative numbers (defaults to "%n").

Field is %n for the currency amount in words.

  • :negative_format - Sets the format for negative numbers (defaults to prepending "minus" to the number in words).

Field is %n for the currency amount in words (same as format).

Examples

number_to_currency_in_words(123456.50)
\=> one hundred and twenty-three thousand four hundred and fifty-six dollars, fifty cents
number_to_currency_in_words(123456.50, :connector => ’ and ’)
\=> one hundred and twenty-three thousand four hundred and fifty-six dollars and fifty cents
number_to_currency_in_words(123456.50, :locale => :fr, :connector => ’ et ’)
\=> cent vingt-trois mille quatre cent cinquante-six dollars et cinquante cents
number_to_currency_in_words(80300.80, :locale => :fr, :currency => :euro, :connector => ’ et ’)
\=> quatre-vingt mille trois cents euros et quatre-vingts centimes

Options only available for :en locale

  • :delimiter - Sets the thousands delimiter (defaults to false).
  • :skip_and - Skips the ‘and’ part in number - US (defaults to false).

Examples

number_to_currency_in_words(201201201.201, :delimiter => true)
\=> two hundred and one million, two hundred and one thousand, two hundred and one dollars, twenty cents
number_to_currency_in_words(201201201.201, :delimiter => true, :skip_and => true)
\=> two hundred one million, two hundred one thousand, two hundred one dollars, twenty cents

[Validate]