Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number precision and average #732

Closed
wagurano opened this issue Oct 19, 2015 · 2 comments
Closed

Number precision and average #732

wagurano opened this issue Oct 19, 2015 · 2 comments

Comments

@wagurano
Copy link

I don't know how to use activerecord aggregation methods(average, count ...).
I expected average result type is real number(float, double ...), but result type is BigDecimal.
How can I fix my code?
Here is my simplified code:


environments

  • jruby 9.0.0.0.pre1 (2.2.0p0) 2015-01-20 d537cab Java HotSpot(TM) Client VM 24.79
    -b02 on 1.7.0_79-b15 +jit [Windows 7-x86]
  • rails 4.2.3
  • activerecord-jdbc-adapter (1.3.18)
  • activerecord-oracle_enhanced-adapter (1.6.3)
  • oracle 10g

table name: data

colunm type
item CHAR(5 BYTE)
base_time CHAR(10 BYTE)
value NUMBER(15,5)

app/model/xxx_data.rb

    class XxxData  < ActiveRecord::Base
        self.table_name = "xxx_yyydata"
        def self.test
          where(base_time: '2012030100'..'2012033123', item: 'XXXYY').average(:value)
        end
    end

Test

$ rails c

    Xxxdata.test
    => #<BigDecimal:c56cbd,'8.0',1(4)>  # exptected 8.4
@yahonda
Copy link
Collaborator

yahonda commented Nov 4, 2015

Would you update your testcase i.e. such as which value inserted to value column.

@yahonda
Copy link
Collaborator

yahonda commented Jan 25, 2016

Closing this since no feedback available.

@yahonda yahonda closed this as completed Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants