Method: Numeric#named

Defined in:
lib/nreadable.rb

#named(precision = 1) ⇒ String

Creates a representation of the number using the short scale large-number naming system with english words. You can change this by modifying the NUMBER_NAMING constant.

Examples:

2000.named #=> "2 thousand"
2_310_000.named #=> "2.3 million"

Raises:

  • (ArgumentError)


136
137
138
139
140
141
142
143
144
# File 'lib/nreadable.rb', line 136

def named( precision = 1 )
  raise ArgumentError, "negative precision" if precision < 0
  return self.to_s if self < 1000 and self > -1000
  return self.to_s if self.is_a? Float and !self.finite?

  number, exponent = base_and_exponent(1000)
  result = nreadable_base_s( number, precision )
  "#{result} #{NUMBER_NAMING[exponent]}"
end