Inconsistent result of #sum

21 views
Skip to first unread message

Mengxi Liao

unread,
Feb 24, 2016, 4:43:42 PM2/24/16
to Ruby on Rails: Talk
For some reason the following two queries return different results

Where there is only one activity record and price is 3.63 and quantity is 16.19, the following codes return results of different rounding.

sum("CEIL(`activities`.quantity/60) * 60 / 3600 * `activities`.price").to_s

"58.81"

sum("CEIL(`activities`.quantity/60) * 60 / 3600 * `activities`.price * 1").to_s

"58.806" # this is the correct one


I have checked the raw sql and both return 58.806.


I believe this is a bug for the sum method.


Rob Biedenharn

unread,
Feb 24, 2016, 6:51:20 PM2/24/16
to rubyonra...@googlegroups.com
0 < 16.19 / 60 ≤ 1

so the ceiling of that should be 1

1 * 60.0 / 3600 * 3.63 == 0.0605

so unless you also have a bug in your CEIL() function, I don't see how the problem can be in the sum()

what are you really doing?

-Rob


Reply all
Reply to author
Forward
0 new messages