This project is archived and is in readonly mode.

#6253 ✓stale
Don Wilson

sqlite3 Float issue

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

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?

Comments and changes to this ticket

  • Don Wilson

    Don Wilson January 5th, 2011 @ 04:29 PM

    • Title changed from “sqlite3-ruby Float issue” to “sqlite3 Float issue”
  • rails

    rails April 9th, 2011 @ 01:00 AM

    • 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.

  • rails

    rails April 9th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages