create table test_tables (
id number(38) primary key,
name varchar2(50),
age number(5),
gender varchar2(10),
point number(5,2)
);
insert into test_tables values (1,'name1',20,'male',80.5);
insert into test_tables values (2,'name2',21,'female',60.5);
insert into test_tables values (3,'name3',23,'male',90.5);
insert into test_tables values (4,'name4',19,'male',79.5);
insert into test_tables values (5,'name5',18,'female',80.5);
The result of TestTable.sum(:point) is 391,
why not 391.5?
I check rdoc,there are some description:
The value is returned with the same data type of the column
But in my case,the type of ‘point’ is number(5,2).
It’s not a float?
I’m not especially familiar with SQLite but I think you should be using a DECIMAL type in your create table statement. More details:
Active Record SQLite Type Mapping
SQLite Types
Be careful of this issue though. It seems that the sqlite3 ruby driver insists on creating Float ruby objects rather than BigDecimal for DECIMAL query results.