Helper methods using numbers

The following were the list of ‘NumberHelper’ methods that can be used inside your view files:

number_to_currency:
number_to_currency(1234567890.50) # => $1,234,567,890.50
number_to_currency(1234567890.50, :unit => “£”, :separator => “,”, :delimiter => “”, :format => “%n %u”) # => 1234567890,50 £
number_to_currency(1234567890.50, :unit => “£”, :separator => “.”, :delimiter => “,”, :format => “%n %u”) # => 1,234,567,890.50 £
number_to_human_size:
number_to_human_size(1234) # => 1.2 KB
number_to_human_size(1234567, :precision => 0) # => 1 MB
number_to_human_size(1234567, :precision => 2, :separator => ‘,’) # => 1,18 MB
number_to_percentage:
number_to_percentage(100) # => 100.000%
number_to_percentage(1000, :delimiter => ‘.’, :separator => ‘,’, :precision => 5) # => 1.000,00000%
number_to_phone:
number_to_phone(5551234) # => 555-1234
number_to_phone(1235551234, :delimiter => ” “) # => 123 555 1234
number_to_phone(1235551234, :area_code => true, :extension => 555) # => (123) 555-1234 x 555
number_to_phone(1235551234, :country_code => 1, :extension => 1343, :delimiter => “.”) # => +1.123.555.1234 x 1343
number_with_delimiter:
number_with_delimiter(12345678) # => 12,345,678
number_with_delimiter(98765432.98, :delimiter => ” “, :separator => “,”) # => 98 765 432,98
number_with_precision:
number_with_precision(111.2345) # => 111.235
number_with_precision(1111.2345, :precision => 2, :separator => ‘,’, :delimiter => ‘.’) # => 1.111,23

Advertisements