Skip to content

Instantly share code, notes, and snippets.

@tiagoefmoraes
Created August 26, 2013 12:46
Show Gist options
  • Save tiagoefmoraes/6341073 to your computer and use it in GitHub Desktop.
Save tiagoefmoraes/6341073 to your computer and use it in GitHub Desktop.
Ruby BigDecimal problems
#http://stackoverflow.com/questions/3039650/ruby-bigdecimal-sanity-check-floating-point-newb/3040859#3040859
9999999999999999900000000.0.to_d.to_s # => "10000000000000000000000000.0"
'9999999999999999900000000.0'.to_d.to_s # => "9999999999999999900000000.0"
(1.0e+25.to_d - 9999999999999999900000000.0.to_d).to_s # => "0.0"
('1.0e+25'.to_d - '9999999999999999900000000.0'.to_d).to_s # => "100000000.0"
(139.25.to_d + 74.79.to_d).to_s # => "214.04000000000001"
('139.25'.to_d + '74.79'.to_d).to_s # => "214.04"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment