Skip to content

Instantly share code, notes, and snippets.

@jarmo
Created October 16, 2010 16:01
Show Gist options
  • Select an option

  • Save jarmo/629958 to your computer and use it in GitHub Desktop.

Select an option

Save jarmo/629958 to your computer and use it in GitHub Desktop.
require 'bigdecimal'
class Float
[:+, :-, :/, :*].each do |op|
define_method(op) do |other|
BigDecimal.new(self.to_s).
send(op, BigDecimal.new(other.to_s))
end
end
end
a = 1.2
b = 1.0
c = 0.2
puts a - b == c
puts a * 10 - b * 10 == c * 10
b = BigDecimal.new("1.0")
puts a - b == c
puts a * 10 - b * 10 == c * 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment