Pretty prints (formats and approximates) a number in a way it is more
readable by humans (eg.: 1200000000 becomes “1.2 Billion”). This is
useful for numbers that can get very large (and too hard to read).

You can also define you own unit-quantifier names if you want to use other
decimal units (eg.: 1500 becomes “1.5 kilometers”, 0.150 becomes “150
mililiters”, etc). You may define a wide range of unit quantifiers, even
fractional ones (centi, deci, mili, etc).

Options

:locale - Sets the locale to be used for formatting (defaults
to current locale).

:precision - Sets the precision of the number (defaults to 3).

:significant - If true, precision will be the # of
significant_digits. If false, the # of fractional digits (defaults
to true)

:separator - Sets the separator between the fractional and
integer digits (defaults to “.”).

# File actionpack/lib/action_view/helpers/number_helper.rb, line 441def number_to_human(number,options={})options.symbolize_keys!number=beginFloat(number)rescueArgumentError,TypeErrorifoptions[:raise]raiseInvalidNumberError,numberelsereturnnumberendenddefaults=I18n.translate(:'number.format',:locale=>options[:locale],:default=>{})human=I18n.translate(:'number.human.format',:locale=>options[:locale],:default=>{})defaults=defaults.merge(human)options=options.reverse_merge(defaults)#for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale filesoptions[:strip_insignificant_zeros]=trueifnotoptions.key?(:strip_insignificant_zeros)units=options.delete:unitsunit_exponents=caseunitswhenHashunitswhenString,SymbolI18n.translate(:"#{units}",:locale=>options[:locale],:raise=>true)whennilI18n.translate(:"number.human.decimal_units.units",:locale=>options[:locale],:raise=>true)elseraiseArgumentError,":units must be a Hash or String translation scope."end.keys.map{|e_name|DECIMAL_UNITS.invert[e_name]}.sort_by{|e|-e}number_exponent=number!=0?Math.log10(number.abs).floor:0display_exponent=unit_exponents.find{|e|number_exponent>=e}||0number/=10**display_exponentunit=caseunitswhenHashunits[DECIMAL_UNITS[display_exponent]]whenString,SymbolI18n.translate(:"#{units}.#{DECIMAL_UNITS[display_exponent]}",:locale=>options[:locale],:count=>number.to_i)elseI18n.translate(:"number.human.decimal_units.units.#{DECIMAL_UNITS[display_exponent]}",:locale=>options[:locale],:count=>number.to_i)enddecimal_format=options[:format]||I18n.translate(:'number.human.decimal_units.format',:locale=>options[:locale],:default=>"%n %u")formatted_number=number_with_precision(number,options)decimal_format.gsub(/%n/,formatted_number).gsub(/%u/,unit).strip.html_safeend