Module | Numeric::Transformer |
In: |
lib/merb-helpers/core_ext/numeric.rb
|
Adds a new format to the existing transforming formats
format <Hash>: | format defining how to transform numeric values |
Changes the default format to use when transforming a Numeric instance
format_code <Symbol>: | format name to use as the new default format |
Hash: | a hash representing the default format |
Converts a numeric value representing minutes into a string representing an hour value
number<Numeric>: | Numeric value representing minutes to convert in hours |
String: | a string representing the numeric value converted in hours |
minutes_to_hours(315) => "05:15"
Formats a number into a currency string (e.g., $13.65). You can specify a format to use and even overwrite some of the format options.
number<Numeric>: | Numeric value to convert |
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
to_currency(1234567890.506, :US, :precision => 1) # => "$1,234,567,890.5" to_currency(1234567890.516, :FR) # =>"1 234 567 890,52€" to_currency(1234567890.516, :US, :unit => "€") # =>"€1,234,567,890.52" to_currency(1234567890.506, :US, :precision => 3, :unit => "€") # => "€1,234,567,890.506" to_currency(1234567890.506, :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.
number<Numeric>: | Numeric value to convert |
String: | a string representing the number converted into a 2 digits string. |
two_digits(5-3) # => "02"
Formats a number 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.
with_delimiter(12345678) # => 12,345,678 with_delimiter(12345678.05) # => 12,345,678.05 with_delimiter(12345678, :FR) # => 12.345.678 with_delimiter(12345678, :US) # => 12,345,678
Formats a number 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
with_precision(111.2345) # => 111.235 with_precision(111.2345, :UK, :precision => 1) # => "111.2" with_precision(1234.567, :US, :precision => 1, :separator => ’,’, :delimiter => ’-’) # => "1-234,6"