H
Henrik Horneber
Hi!
I stumbled over something while toying around with BigDecimal
require 'bigdecimal'
==>true
a = 2.12
==>2.12
b = BigDecimal.new(a.to_s).to_f
==>2.12
a == b
==>true
a = 20.12
==>20.12
b = BigDecimal.new(a.to_s).to_f
==>20.12
a == b
==>false
a.class == b.class
==>true
a.to_s == b.to_s
==>true
# in short
a == b
==>false # and then sometimes its true
a == b.to_s.to_f
==>true
b == b.to_s.to_f
==>false
#even though
b.class == b.to_s.to_f.class
==>true
a.class == b.class
==>true
seems a little strange to me.
what's going on?
Henrik
D:\>ruby -v
ruby 1.8.2 (2004-07-29) [i386-mswin32]
I stumbled over something while toying around with BigDecimal
require 'bigdecimal'
==>true
a = 2.12
==>2.12
b = BigDecimal.new(a.to_s).to_f
==>2.12
a == b
==>true
a = 20.12
==>20.12
b = BigDecimal.new(a.to_s).to_f
==>20.12
a == b
==>false
a.class == b.class
==>true
a.to_s == b.to_s
==>true
# in short
a == b
==>false # and then sometimes its true
a == b.to_s.to_f
==>true
b == b.to_s.to_f
==>false
#even though
b.class == b.to_s.to_f.class
==>true
a.class == b.class
==>true
seems a little strange to me.
what's going on?
Henrik
D:\>ruby -v
ruby 1.8.2 (2004-07-29) [i386-mswin32]