Sha256: c889517c895c9f70cda15edf4ee6de1b57f73e5fa9b8bbd4c6da24f198351694

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

module FlydataCore
module TableDef

# Collection of methods to covert values
module ValueConv
  # currency format string -> decimal string
  def self.strip_currency_format(value)
    # It's impossible to determine a decimal point of a currency sting without
    # knowing its format.  Here, we're making a best effort guess to support
    # as many currency formats as we can without knowing the format.
    value = value.gsub(/[^0-9\.,]/, '') # remove all chars but numbers and possible decimal point chars

    whole_part = value
    fractional_part = nil
    if idx = value.rindex(/[\.,]/)
      if idx == value.size - 3
        # it's the decimal point with two digit fraction
        whole_part = value[0...idx]
        fractional_part = value[-2..-1]
      end
    end
    value = whole_part.gsub(/[^0-9]/, '')
    value += ".#{fractional_part}" if fractional_part
    value
  end
end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flydata-0.7.1 flydata-core/lib/flydata-core/table_def/value_conv.rb