BigDecimal to_s does not match to_f

Posted by Chris Bisignani on Stack Overflow See other posts from Stack Overflow or by Chris Bisignani
Published on 2010-04-01T21:10:31Z Indexed on 2010/04/01 21:13 UTC
Read the original article Hit count: 296

Filed under:
|

Is the BigDecimal class broken? It seems like the following should never, ever occur: Note that a.to_f != a.to_s.to_f

a.class => BigDecimal

a.to_f => 18658.1072928

a.to_s => "10865.81072928"

b.class => BigDecimal

b.to_f => 10000.0

b.to_s => "10000.0"

(a - b).to_f => 865.81072928

a.to_f - b.to_f => 8658.1072928

Any ideas as to what might be going wrong?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about bigdecimal