6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/plurimath/formatter/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
|