Module | ActionView::Helpers::NumberHelper |
In: |
lib/action_view/helpers/number_helper.rb
|
Provides methods for converting a number into a formatted string that currently represents one of the following forms: phone number, percentage, money, or precision level.
Formates a number into a currency string. The options hash can be used to customize the format of the output. The number can contain a level of precision using the precision key; default is 2 The currency type can be set using the unit key; default is "$" The unit separator can be set using the separator key; default is "." The delimiter can be set using the delimiter key; default is "," Examples:
number_to_currency(1234567890.50) => $1,234,567,890.50 number_to_currency(1234567890.506) => $1,234,567,890.51 number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""}) => £1234567890,50
Returns a formatted-for-humans file size.
Examples:
human_size(123) => 123 Bytes human_size(1234) => 1.2 KB human_size(12345) => 12.1 KB human_size(1234567) => 1.2 MB human_size(1234567890) => 1.1 GB
Formats a number as into a percentage string. The options hash can be used to customize the format of the output. The number can contain a level of precision using the precision key; default is 3 The unit separator can be set using the separator key; default is "." Examples:
number_to_percentage(100) => 100.000% number_to_percentage(100, {:precision => 0}) => 100% number_to_percentage(302.0574, {:precision => 2}) => 302.06%
Formats a number into a US phone number string. The options can be hash used to customize the format of the output. The area code can be surrounded by parenthesis by setting +:area_code+ to true; default is false The delimiter can be set using +:delimiter+; default is "-" Examples:
number_to_phone(1235551234) => 123-555-1234 number_to_phone(1235551234, {:area_code => true}) => (123) 555-1234 number_to_phone(1235551234, {:delimiter => " "}) => 123 555 1234 number_to_phone(1235551234, {:area_code => true, :extension => 555}) => (123) 555-1234 x 555