From: Reuven Lerner Date: 2010-05-17T20:25:42+09:00 Subject: [ruby-core:30275] [Backport #3304] Bug in BigDecimal#to_f Backport #3304: Bug in BigDecimal#to_f http://redmine.ruby-lang.org/issues/show/3304 Author: Reuven Lerner Status: Open, Priority: Normal I'm using ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0], from OS X Snow Leopard. I am using BigDecimal in a project that requires a large number of significant figures after the decimal point. I know that there are issues using floats for exact math, but I think that I have discovered something surprising even when you take that into consideration: In IRB: >> require 'bigdecimal' => true >> number = BigDecimal.new('2.50000') => # >> number.to_f => 2.5 >> number += BigDecimal.new('1000000') => # >> number.to_f => 1002500.0 >> number.to_s("F").to_f => 1000002.5 Am I missing something? I'd like to think that this is my mistake, but these results definitely violated the Principle of Least Surprise! Reuven ---------------------------------------- http://redmine.ruby-lang.org