NumberHelper
The NumberHelper class provides convenience methods for formatting numbers:
number_to_currencyTurns 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_sizeTurns file-size byte counts into more typical human representations, like 12 GB.
number_to_percentageTurns a number into a percent value. You can select the
:precision(normally three digits after the decimal), and the:separator(normally.).number_to_phoneTurns 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_delimiterFormats a number with a given
:delimiterbetween thousands (,by default) and decimal:separator(.by default).number_with_precisionFormats a number to present as many digits after the decimal point as are specified in the second argument (three is the default).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access