O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

NumberHelper

The NumberHelper class provides convenience methods for formatting numbers:

number_to_currency

Turns a number into a currency representation. You can select the :unit (denomination), :separator (normally .), :delimiter (normally , ), :format (whether the currency comes before or after the number), and :precision (normally 2).

number_to_human_size

Turns file-size byte counts into more typical human representations, like 12 GB.

number_to_percentage

Turns a number into a percent value. You can select the :precision (normally three digits after the decimal), and the :separator (normally .).

number_to_phone

Turns a number into an American-style telephone number. You can specify a country code, extension, delimiter, and whether or not the area code has parentheses, but you can’t specify how the numbers are broken down.

number_with_delimiter

Formats a number with a given :delimiter between thousands (, by default) and decimal :separator (. by default).

number_with_precision

Formats a number to present as many digits after the decimal point as are specified in the second argument (three is the default).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required