Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

sqlite3 Float issue

#6253

I'm submitting this for help collaborating on what should be done, if anything.

Example of the issue

Here, I am summing -40.25, 100, and -34.59 in the database:

irb(main):001:0> my_envelope.bank_transactions.sum(:amount)
=> #<BigDecimal:1011be570,'0.2515999999 9999997E2',27(27)>

The sqlite3 methods for retrieving this data from the row returns a double. This means that we're dealing with normal Float precision issues from the moment it comes out of the database. Then, since the column type is decimal, rails converts the number from Float to BigDecimal. Before Ruby 1.9, Ruby would have rounded this number to 25.16 and then we would see the correct number in the BigDecimal.

My issue with this is that I think we can assume that people should know about precision problems with a Float, but when Rails hands them a BigDecimal, I think they should be confident that it represents the actual number.

What do we do?

Would it be a good idea to round these numbers for the user before we send it to them as a BigDecimal? We could even just call BigDecimal.round(12) to round to the 12th decimal place or something. Any thoughts?

Reported by Don Wilson · January 5th, 2011 @ 04:27 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Don Wilson
    Don Wilson
    • Title changed from sqlite3-ruby Float issue to sqlite3 Float issue

    January 5th, 2011 @ 04:29 PM

  2. rails
    rails
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    April 9th, 2011 @ 01:00 AM

  3. rails
    rails
    • State changed from open to stale

    April 9th, 2011 @ 01:00 AM