Sha256: 0e24fb8c8dc7e14cf26a963457ad0cf6c55f7e1235df10d0aa62deb6ed0a1459

Contents?: true

Size: 615 Bytes

Versions: 4

Compression:

Stored size: 615 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Formatters
    class AbbreviatedNumberFormatter < NumberFormatter

      protected

      def transform_number(number)
        within = number < TwitterCldr::DataReaders::NumberDataReader::NUMBER_MAX &&
          number >= TwitterCldr::DataReaders::NumberDataReader::NUMBER_MIN

        if within
          power = (((number.to_s.length - 1) / 3) * 3).floor
          factor = (10 ** power).to_f
          number / factor
        else
          number
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter_cldr-3.0.3 lib/twitter_cldr/formatters/numbers/abbreviated/abbreviated_number_formatter.rb
twitter_cldr-3.0.2 lib/twitter_cldr/formatters/numbers/abbreviated/abbreviated_number_formatter.rb
twitter_cldr-3.0.1 lib/twitter_cldr/formatters/numbers/abbreviated/abbreviated_number_formatter.rb
twitter_cldr-3.0.0 lib/twitter_cldr/formatters/numbers/abbreviated/abbreviated_number_formatter.rb