Convert int to real in sqlite

Split in sqlite returns an integer value

sqlite> select totalUsers/totalBids from (select (select count(*) from Bids) as totalBids , (select count(*) from Users) as totalUsers) A; 1 

Is it possible to come up with a result to get the real value of the separation result?

+52
casting sql sqlite division
Nov 29 2018-11-11T00:
source share
4 answers

Just multiply one of the numbers by 1.0 :

 SELECT something*1.0/total FROM somewhere 

This will give you floating point division instead of integer division.

+90
Nov 29 '11 at 3:53
source share

In Sqlite, dividing an integer by another integer will always round to the nearest integer.

Therefore, if you list your counter on a float:

 SELECT CAST(field1 AS FLOAT) / field2 
+31
Dec 02 '13 at 10:08
source share
 select cast ( ( select 1 ) as real ); 

https://www.sqlite.org/lang_expr.html#castexpr

+7
Aug 31 '13 at 17:18
source share

or if you want to update a column based on a text column:

 UPDATE table_with_fields SET real_field=cast(field_with_txt AS real) 
+1
Jul 13 '16 at 10:24
source share



All Articles