converting int to real in sqlite

蓝咒 提交于 2019-11-27 07:02:19

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.

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
select cast ( ( select 1 ) as real );

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

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

UPDATE table_with_fields SET real_field=cast(field_with_txt AS real)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!