converting int to real in sqlite

前端 未结 4 2048
天命终不由人
天命终不由人 2020-12-04 15:03

Division in sqlite return integer value

sqlite> select totalUsers/totalBids from 
(select (select count(*) from Bids) as totalBids , 
(select count(*) fro         


        
相关标签:
4条回答
  • 2020-12-04 15:43

    In Sqlite the division of an integer by another integer will always round down to the closest integer.

    Therefore if you cast your enumerator to a float:

    SELECT CAST(field1 AS FLOAT) / field2
    
    0 讨论(0)
  • 2020-12-04 15:45
    select cast ( ( select 1 ) as real );
    

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

    0 讨论(0)
  • 2020-12-04 15:47

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

    UPDATE table_with_fields SET real_field=cast(field_with_txt AS real)
    
    0 讨论(0)
  • 2020-12-04 15:53

    Just multiply one of the numbers by 1.0:

    SELECT something*1.0/total FROM somewhere
    

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

    0 讨论(0)
提交回复
热议问题