Class Numeric
In: merb-helpers/lib/merb-helpers/core_ext/numeric.rb
Parent: Object

Methods

Classes and Modules

Module Numeric::Transformer

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"

[Source]

     # File merb-helpers/lib/merb-helpers/core_ext/numeric.rb, line 383
383:   def minutes_to_hours
384:     Transformer.minutes_to_hours(self)
385:   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"

[Source]

     # File merb-helpers/lib/merb-helpers/core_ext/numeric.rb, line 352
352:   def to_currency(format_name = nil, options = {})
353:     Transformer.to_currency(self, format_name, options)
354:   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"

[Source]

     # File merb-helpers/lib/merb-helpers/core_ext/numeric.rb, line 366
366:   def two_digits
367:     Transformer.two_digits(self)
368:   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

[Source]

     # File merb-helpers/lib/merb-helpers/core_ext/numeric.rb, line 294
294:   def with_delimiter(format_name = nil, options = {})
295:     Transformer.with_delimiter(self, format_name, options)
296:   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"

[Source]

     # File merb-helpers/lib/merb-helpers/core_ext/numeric.rb, line 321
321:   def with_precision(format_name = nil, options = {})
322:     Transformer.with_precision(self, format_name, options)
323:   end

[Validate]