Class | Numeric |
In: |
lib/merb-helpers/core_ext/numeric.rb
|
Parent: | Object |
Formats into a currency string (e.g., $13.65). You can specify a format to use and even overwrite some of the format options.
format_name<Symbol>: | name of the format to use |
options<Hash>: | options which will overwrite the used format |
String: | a string representing the number converted in currency |
:precision - Sets the level of precision :unit - Sets the denomination of the currency :format - Sets the format of the output string (defaults to "%u%n"). The field types are:
%u The currency unit %n The number
1234567890.506.to_currency(:US) # => "$1,234,567,890.51" 1234567890.506.to_currency(:US, :precision => 1) # => "$1,234,567,890.5" 1234567890.516.to_currency(:FR) # =>"1 234 567 890,52€" 1234567890.516.to_currency(:US, :unit => "€") # =>"€1,234,567,890.52" 1234567890.506.to_currency(:US, :precision => 3, :unit => "€") # => "€1,234,567,890.506" 1234567890.506.to_currency(:AU, :unit => "$AUD", :format => ’%n %u’) # => "1,234,567,890.51 $AUD"
Formats a number into a two digit string. Basically it prepends an integer to a 2 digits string.
String: | a string representing the number converted into a 2 digits string. |
(5-3).two_digits # => "02"
Formats with with grouped thousands using delimiter (e.g., 12,324). You can pass another format to format the number differently.
format_name<Symbol>: | name of the format to use |
options<Hash>: | options which will overwrite the used format |
String: | a string representing the delimited number |
:delimiter - Overwrites the thousands delimiter. :separator - Overwrites the separator between the units.
12345678.with_delimiter # => 12,345,678 12345678.05.with_delimiter # => 12,345,678.05 12345678.with_delimiter(:FR) # => 12.345.678 12345678.with_delimiter(:US) # => 12,345,678
Formats with a level of :precision (e.g., 112.32 has a precision of 2). You can pass another format to use and even overwrite the format‘s options.
format_name<Symbol>: | name of the format to use |
options<Hash>: | options which will overwrite the used format |
String: | a string representing the delimited number |
:precision - Overwrites the level of precision :separator - Overwrites the separator between the units :delimiter - Overwrites the thousands delimiter
111.2345.with_precision # => 111.235 111.2345.with_precision(:UK, :precision => 1) # => "111.2" 1234.567.with_precision(:US, :precision => 1, :separator => ’,’, :delimiter => ’-’) # => "1-234,6"