Sha256: a24a0a5e4a2a038dca859ccbdcecb53432abc36df981f4600120fd62b4790894

Contents?: true

Size: 519 Bytes

Versions: 6

Compression:

Stored size: 519 Bytes

Contents

# frozen_string_literal: true

class String
  # Converts this string to a float and then to a Money object in the default currency.
  # It multiplies the converted numeric value by 100 and treats that as cents.
  #
  # NOTE!!!
  # This is overriden as per the default Money .to_money because it assumes
  # a different default currency...
  #
  # '100'.to_money => #<Money @cents=10000>
  # '100.37'.to_money => #<Money @cents=10037>
  def to_money(currency = nil)
    Money.new((to_f * 100).round, currency)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
money_extensions-1.5.0 lib/money_extensions/string.rb
money_extensions-1.4.0 lib/money_extensions/string.rb
money_extensions-1.3.0 lib/money_extensions/string.rb
money_extensions-1.2.0 lib/money_extensions/string.rb
money_extensions-1.1.0 lib/money_extensions/string.rb
money_extensions-1.0.0 lib/money_extensions/string.rb