Class: TwitterCldr::Formatters::NumberFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/formatter/twitter_cldr_rb/number_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(tokens, number, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/plurimath/formatter/twitter_cldr_rb/number_formatter.rb', line 6

def format(tokens, number, options = {})
  options[:precision] ||= precision_from(number)
  options[:type] ||= :decimal

  prefix, suffix, integer_format, fraction_format = *partition_tokens(tokens)
  number = truncate_number(number, integer_format.format.length)

  int, fraction = parse_number(number, options)
  result = integer_format.apply(int, options)
  result << fraction_format.apply(fraction, options, int) if fraction

  number_system.transliterate(
    "#{prefix.to_s}#{result}#{suffix.to_s}"
  )
end