method
convert
v5.0.0.1 -
Show latest stable
- Class:
ActiveSupport::NumberHelper::NumberToHumanConverter
convert()public
No documentation available.
# File activesupport/lib/active_support/number_helper/number_to_human_converter.rb, line 11
def convert # :nodoc:
@number = Float(number)
# for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
unless options.key?(:strip_insignificant_zeros)
options[:strip_insignificant_zeros] = true
end
units = opts[:units]
exponent = calculate_exponent(units)
@number = number / (10 ** exponent)
until (rounded_number = NumberToRoundedConverter.convert(number, options)) != NumberToRoundedConverter.convert(1000, options)
@number = number / 1000.0
exponent += 3
end
unit = determine_unit(units, exponent)
format.gsub('%n'.freeze, rounded_number).gsub('%u'.freeze, unit).strip
end