class Numeric
Public Instance Methods
Converts a numeric
value representing minutes into a string
representing an hour value
Parameters¶ ↑
- number<Numeric>
-
Numeric value representing minutes to convert in hours
Returns¶ ↑
- String
-
a string representing the numeric value converted in hours
Examples¶ ↑
315.minutes_to_hours => “05:15”
# File lib/merb-helpers/core_ext/numeric.rb, line 383 def minutes_to_hours Transformer.minutes_to_hours(self) end
Formats into a currency string (e.g., $13.65). You can specify a format to use and even overwrite some of the format options.
Parameters¶ ↑
- format_name<Symbol>
-
name of the format to use
- options<Hash>
-
options which will overwrite the used format
Returns¶ ↑
- String
-
a string representing the number converted in currency
Options¶ ↑
: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
Examples¶ ↑
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”
# File lib/merb-helpers/core_ext/numeric.rb, line 352 def to_currency(format_name = nil, options = {}) Transformer.to_currency(self, format_name, options) end
Formats a number
into a two digit string. Basically it
prepends an integer to a 2 digits string.
Returns¶ ↑
- String
-
a string representing the number converted into a 2 digits string.
Examples¶ ↑
(5-3).two_digits # => “02”
# File lib/merb-helpers/core_ext/numeric.rb, line 366 def two_digits Transformer.two_digits(self) end
Formats with with grouped thousands using delimiter
(e.g.,
12,324). You can pass another format to format the number differently.
Parameters¶ ↑
- format_name<Symbol>
-
name of the format to use
- options<Hash>
-
options which will overwrite the used format
Returns¶ ↑
- String
-
a string representing the delimited number
Options¶ ↑
:delimiter - Overwrites the thousands delimiter. :separator - Overwrites the separator between the units.
Examples¶ ↑
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
# File lib/merb-helpers/core_ext/numeric.rb, line 294 def with_delimiter(format_name = nil, options = {}) Transformer.with_delimiter(self, format_name, options) end
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.
Parameters¶ ↑
- format_name<Symbol>
-
name of the format to use
- options<Hash>
-
options which will overwrite the used format
Returns¶ ↑
- String
-
a string representing the delimited number
Options¶ ↑
:precision - Overwrites the level of precision :separator - Overwrites the separator between the units :delimiter - Overwrites the thousands delimiter
Examples¶ ↑
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”
# File lib/merb-helpers/core_ext/numeric.rb, line 321 def with_precision(format_name = nil, options = {}) Transformer.with_precision(self, format_name, options) end