As we all well know, Rails does a lot of work for us (yippie! more time for ps2!) in the form of Helpers.
ex. for helpers is the FormHelper for form fields creation
Each one of the pre-made helpers, desigend to preforms an action which in other web-development frameworks and languages would take you hours/days/years (if you are married). the only objective of these pre-methods is to DRY your code in a way that it is also readable, and also correct (not all of us are super-programmers).
yes, the NumberHelper provids basic methods for converting numbers to a string form such as: phone number, percentage or money (there are more, i’m just lazy)
NumberHelper methods are as follows:
Returns a readable file-size string
human_size(777) => 777 bytes human_size(7777) => 7.7 KB
Formats the number into a currency readable string, output can be formatted using the options parameter
number_to_currency(1234.50) => $1,234.50
number_to currency(1234.50,{:unit => "£", :delimiter => "-"}) => £1-234.50
Formats the number into a precentage string. output can be formatted using the options parameter.
number_to_percentage(100) => 100.000%
number_to_percentage(100, {:precision => 0}) => 100%
Formats a number into a US phone number string. output can be formatted using the options parameter.
The area code can be surrounded by parentheses by setting rea_code to true; default is false The delimiter can be set using elimiter; default is ”-”
number_to_phone(1235551234) => 123-555-1234
number_to_phone(1235551234, {:area_code => true}) => (123) 555-1234
Formats a number to a delimeterd string
number_with_delimiter(1234) => 1,234
Formats a number to a precised string
number_with_precision(1200.1234) => 1200.123
—Elad Meidar elad@creopolis.com
How do I format a 2 digit number to a 5 digit number? ex. from 12 to 00012
Like this:
"%05.0f" % 12 => "00012"
Great piece of work, very helpful
As we all well know, Rails does a lot of work for us (yippie! more time for ps2!) in the form of Helpers.
ex. for helpers is the FormHelper for form fields creation
Each one of the pre-made helpers, desigend to preforms an action which in other web-development frameworks and languages would take you hours/days/years (if you are married). the only objective of these pre-methods is to DRY your code in a way that it is also readable, and also correct (not all of us are super-programmers).
yes, the NumberHelper provids basic methods for converting numbers to a string form such as: phone number, percentage or money (there are more, i’m just lazy)
NumberHelper methods are as follows:
Returns a readable file-size string
human_size(777) => 777 bytes human_size(7777) => 7.7 KB
Formats the number into a currency readable string, output can be formatted using the options parameter
number_to_currency(1234.50) => $1,234.50
number_to currency(1234.50,{:unit => "£", :delimiter => "-"}) => £1-234.50
Formats the number into a precentage string. output can be formatted using the options parameter.
number_to_percentage(100) => 100.000%
number_to_percentage(100, {:precision => 0}) => 100%
Formats a number into a US phone number string. output can be formatted using the options parameter.
The area code can be surrounded by parentheses by setting rea_code to true; default is false The delimiter can be set using elimiter; default is ”-”
number_to_phone(1235551234) => 123-555-1234
number_to_phone(1235551234, {:area_code => true}) => (123) 555-1234
Formats a number to a delimeterd string
number_with_delimiter(1234) => 1,234
Formats a number to a precised string
number_with_precision(1200.1234) => 1200.123
—Elad Meidar elad@creopolis.com
How do I format a 2 digit number to a 5 digit number? ex. from 12 to 00012
Like this:
"%05.0f" % 12 => "00012"
Great piece of work, very helpful