module ActiveSupport::NumberHelper

def number_to_human(number, options = {})

number_to_human(0.34, units: :distance) # => "34 centimeters"
number_to_human(1, units: :distance) # => "1 meter"
number_to_human(343, units: :distance, precision: 1) # => "300 meters"
number_to_human(54393498000, units: :distance) # => "54.4 gazillion-distance"
number_to_human(54393498, units: :distance) # => "54400 kilometers"
number_to_human(543934, units: :distance) # => "544 kilometers"

Then you could do:

billion: "gazillion-distance"
other: "kilometers"
one: "kilometer"
thousand:
other: "meters"
one: "meter"
unit:
other: "centimeters"
one: "centimeter"
centi:
distance:

If in your I18n locale you have:

number_to_human(500000, units: { unit: 'ml', thousand: 'lt' }) # => "500 lt"
You can also use your own custom unit quantifiers:

==== Custom Unit Quantifiers

number_to_human(500000000, precision: 5) # => "500 Million"
number_to_human(12345012345, significant_digits: 6) # => "12.345 Billion"

+false+ to change that):
out by default (set :strip_insignificant_zeros to
Non-significant zeros after the decimal separator are stripped

significant: false) # => "1,2 Million"
separator: ',',
number_to_human(1234567, precision: 1,
significant: false) # => "1.2346 Million"
number_to_human(1234567, precision: 4,
number_to_human(489939, precision: 4) # => "489.9 Thousand"
number_to_human(489939, precision: 2) # => "490 Thousand"
number_to_human(1234567890123456789) # => "1230 Quadrillion"
number_to_human(1234567890123456) # => "1.23 Quadrillion"
number_to_human(1234567890123) # => "1.23 Trillion"
number_to_human(1234567890) # => "1.23 Billion"
number_to_human(1234567) # => "1.23 Million"
number_to_human(12345) # => "12.3 Thousand"
number_to_human(1234) # => "1.23 Thousand"
number_to_human(123) # => "123"

==== Examples

* %n - The number
* %u - The quantifier (ex.: 'thousand')
(defaults to "%n %u"). The field types are:
* :format - Sets the format of the output string
*:pico, :femto
*:mili, :micro, :nano,
* *fractionals*: :deci, :centi,
*:quadrillion
*:billion, :trillion,
*:hundred, :thousand, :million,
* *integers*: :unit, :ten,
might have the following keys:
string containing an i18n scope where to find this hash. It
* :units - A Hash of unit quantifier names. Or a
+true+)
insignificant zeros after the decimal separator (defaults to
* :strip_insignificant_zeros - If +true+ removes
to "").
* :delimiter - Sets the thousands delimiter (defaults
fractional and integer digits (defaults to ".").
* :separator - Sets the separator between the
digits (defaults to +true+)
of significant_digits. If +false+, the # of fractional
* :significant - If +true+, precision will be the #
(defaults to 3).
* :precision - Sets the precision of the number
(defaults to current locale).
* :locale - Sets the locale to be used for formatting

==== Options

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

size.
See number_to_human_size if you want to print a file

(and too hard to read).
Billion"). This is useful for numbers that can get very large
is more readable by humans (eg.: 1200000000 becomes "1.2
Pretty prints (formats and approximates) a number in a way it
def number_to_human(number, options = {})
  options = options.symbolize_keys
  return number unless valid_float?(number)
  number = Float(number)
  defaults = format_options(options[:locale], :human)
  options  = defaults.merge!(options)
  #for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
  options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros)
  inverted_du = DECIMAL_UNITS.invert
  units = options.delete :units
  unit_exponents = case units
  when Hash
    units
  when String, Symbol
    I18n.translate(:"#{units}", :locale => options[:locale], :raise => true)
  when nil
    translate_number_value_with_default("human.decimal_units.units", :locale => options[:locale], :raise => true)
  else
    raise ArgumentError, ":units must be a Hash or String translation scope."
  end.keys.map{|e_name| inverted_du[e_name] }.sort_by{|e| -e}
  number_exponent = number != 0 ? Math.log10(number.abs).floor : 0
  display_exponent = unit_exponents.find{ |e| number_exponent >= e } || 0
  number  /= 10 ** display_exponent
  unit = case units
  when Hash
    units[DECIMAL_UNITS[display_exponent]] || ''
  when String, Symbol
    I18n.translate(:"#{units}.#{DECIMAL_UNITS[display_exponent]}", :locale => options[:locale], :count => number.to_i)
  else
    translate_number_value_with_default("human.decimal_units.units.#{DECIMAL_UNITS[display_exponent]}", :locale => options[:locale], :count => number.to_i)
  end
  decimal_format = options[:format] || translate_number_value_with_default('human.decimal_units.format', :locale => options[:locale])
  formatted_number = self.number_to_rounded(number, options)
  decimal_format.gsub(/%n/, formatted_number).gsub(/%u/, unit).strip
end