ruby on rails - Decimal being stored as BigDecimal:4a58c60,'0.7484999999 999999E2',27(27) instead of 74.85 -


i have table created , 1 of columns created as:

t.decimal price 

i created new record doing this:

prices.create(:price => 74.85) 

and record created shows this:

#<price id: 10, price: #<bigdecimal:4925c58,'0.7484999999 999999e2',27(27)>> 

why happen? set 74.85 not 74.849999...

thanks

this floating point error. can use string instead:

prices.create(:price => "74.85") 

note not rails bug, it's way floating point values , bigdecimal work:

bigdecimal.new(74.85, 0)    #=> #<bigdecimal:7fc37cb7c068,'0.7484999999 9999994315 6581139191 98513031e2',45(54)> bigdecimal.new("74.85")     #=> #<bigdecimal:7fc37ce69d48,'0.7485e2',18(18)> 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -