Sha256: f6b8090ec64aeb703a25cf0e529c46109e7a582e2b9c653d1deb0ffb07be0b00
Contents?: true
Size: 1.24 KB
Versions: 3
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module Plurimath module Formatter class NumberFormatter < TwitterCldr::Formatters::NumberFormatter def format(tokens, number, options = {}) options[:precision] ||= precision_from(number) options[:type] ||= :decimal prefix, suffix, integer_format, fraction_format, signif_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 result = signif_format.apply(result, integer_format, fraction_format) number_system.transliterate( "#{prefix.to_s}#{result}#{suffix.to_s}" ) end private def partition_tokens(tokens) [ token_val_from(tokens[0]), token_val_from(tokens[2]), Numbers::Integer.new( tokens[1], data_reader.symbols ), Numbers::Fraction.new( tokens[1], data_reader.symbols ), Numbers::Significant.new( data_reader.symbols, ) ] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
plurimath-0.8.13 | lib/plurimath/formatter/number_formatter.rb |
plurimath-0.8.12 | lib/plurimath/formatter/number_formatter.rb |
plurimath-0.8.11 | lib/plurimath/formatter/number_formatter.rb |