fork download
  1. require 'bigdecimal'
  2.  
  3. class Float
  4. [:+, :-, :/, :*].each do |op|
  5. define_method(op) do |other|
  6. BigDecimal.new(self.to_s).
  7. send(op, BigDecimal.new(other.to_s))
  8. end
  9. end
  10. end
  11.  
  12. a = 1.2
  13. b = 1.0
  14. c = 0.2
  15.  
  16. puts a - b == c
  17. puts a * 10 - b * 10 == c * 10
  18.  
  19. b = BigDecimal.new("1.0")
  20. puts a - b == c
  21. puts a * 10 - b * 10 == c * 10
Success #stdin #stdout 0s 30336KB
stdin
Standard input is empty
stdout
true
true
true
true