Search code examples
sqliteselectmultiplicationoperation

Problem doing multiplication operation in a select between a float and an integer in sqlite


Problem Hi, I have this problem when I do this operation between a float and an integer number.

select codventa, cantidad, precio, cantidad * precio from 
ventas v, detallesventas dv
where v.codventa = 23 and dv.codventa = v.codventa

Instead of 399,96 the result is 396. I don't know why


Solution

  • Sqlite uses ., not , for the decimal point in a floating pointer number (Do any sql databases accept a comma for it?).

    When you multiply a number (4) by a string ('99,99') the leading numeric portion of the string is converted to a number, so you're seeing the result of 4 * 99. (SELECT typeof(precio) FROM yourtable will be text, not real).

    SELECT 4*99,99 returns two columns - one 4*99, one 99, because comma is the column/value separator.

    Some useful reading: