This project is archived and is in readonly mode.
Coerce 0 Average Calculation To Float
Reported by Ken Collins | November 7th, 2008 @ 08:35 PM
Some databases return 0 for a #average calculation. For instance:
Topic.average(:replies_count)
Returns 0 from SQL Server and will bomb when #type_cast_calculated_value is run. I am submitting this patch with high hopes that it can be done in 2.2 release. We are trying to finish the new SQL Server adapter to that release and having all the tests pass would without monkey patching rails would be great!
Cheers.
Comments and changes to this ticket
-
josh November 8th, 2008 @ 02:40 AM
- State changed from new to resolved
- Assigned user set to josh
-
Repository November 8th, 2008 @ 02:47 AM
(from [a7f920f674d234f281d2491ebe6d74710a79e663]) If average value from DB is 0, make sure to convert it to a 0.0 float before calling #to_d on it [#1346 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
Tarmo Tänav November 8th, 2008 @ 11:02 PM
- State changed from resolved to open
What's the point of using BigDecimal at all if we're first converting to float?, the bigdecimal is certainly not going to be any more precise than the float it is made from.
Seems to me that the special case should only be used if the value actually is 0, in which case to_f wouldn't really be needed, one could just use: value && (value == 0 ? 0.0.to_d : value.to_d)
-
Ken Collins November 10th, 2008 @ 05:17 AM
That looks just fine to me. I'll put together another patch.
-
josh November 10th, 2008 @ 06:35 PM
- Milestone cleared.
-
Repository November 10th, 2008 @ 08:17 PM
- State changed from open to resolved
(from [335a31524055c7dd79618ea79b3c18d827e25d3d]) Add simple case when DB calculations returns 0 instead of 0.0 [#1346 state:resolved] http://github.com/rails/rails/co...
-
Ken Collins November 11th, 2008 @ 01:54 PM
Thanks again! My Monday was crushed with bugs from co-workers. Cheers!
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
Attachments
Tags
Referenced by
- 1346 Coerce 0 Average Calculation To Float (from [a7f920f674d234f281d2491ebe6d74710a79e663]) If aver...
- 1346 Coerce 0 Average Calculation To Float (from [335a31524055c7dd79618ea79b3c18d827e25d3d]) Add sim...
- 1368 Make sure any Fixnum returned by a DB sum is type cast to a Float before standard converstion to a BigDecimal. My apologies. Ticket #1346 is incomplete. "Some" DBs will...