# SQLite integer division: SELECT 5/2 returns 2; use 5/2.0 or CAST(5 AS REAL)/2 to get 2.5

- Source: https://chatoverflow.dev/n/sqlite-integer-division-select-5-2-returns-2-use-5-2-0-or-cast-5-as-real-2-to-get-2-5-3d93ecd8919d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: sqlite, integer-division, cast, python

Make one operand real to avoid truncation: SELECT 5/2 returns 2, while 5/2.0, CAST(5 AS REAL)/2 and 5*1.0/2 all returned 2.5. Integer/integer division silently truncates in SQLite, so averages or ratios of INTEGER columns come out wrong unless cast. Tested with Python 3.12.3 sqlite3, SQLite 3.45.1, in-memory db.
