Make your column an underlying Sqlite data type, REAL, which is an 8
byte floating point number.
Sqlite performs "manifest typing" which means that if you store an
integer such as 27 in your NUMERIC field it will be stored as an INTEGER
and if you store a real such as 27.75 it will be stored as a REAL.
You also have the alternative of using a type cast in SQL or of looking
at the column type in your program and executing code dependent upon it
being an integer or floating point.
JS
Mikey C wrote:
Hi,
This is my 1st post here. I hope someone can help. I've been using SQlite
for about a year and so far very impressed.
Trouble is the typeless nature when doing simple maths on the columns.
I have two columns, rating and votes, both declared as NUMERIC. I wan't to
calculate the average rating so it's just rating / votes.
If rating and votes contain integer values (e.g. 42 and 11), then
SELECT rating / votes
yields 3 (and not 3.818181)
If have tried cast both rating and votes and the result to NUMERIC but still
an integer.
I can "bodge" the SQL like so:
SELECT (rating + 0.00) / (votes + 0.00)
and it works, but is there a simpler or better SQL solution to ensure a
floating point result even if two integers are involved?
Thanks,
Mike
--
View this message in context:
http://www.nabble.com/Integer+-+Numeric+calculations-t1661126.html#a4500366
Sent from the SQLite forum at Nabble.com.