SQLite Forum

Division by decimals wrongly returning a rounded int result (works fine when casting to real)
Login
Yeah, exactly that.

But I can actually so some "advanced stuff" like that. For example, I can make that multiplication that you described like this:

```
  T.objects.annotate(
    foo=(Value(Decimal("1.0")) * F("a")) / F("b"),
  )
```

This translates exactly to your suggestion, but based on the fact that django abstracts it I would not expect to need to cast anything to decimal since my columns are already decimal (which I know understand maps to NUMERIC and not REAL). If I was using postgresql/mysql/etc (which I use in production, postgresql), I would not need that workaround.

Note that I use DecimalField (https://docs.djangoproject.com/en/3.2/ref/models/fields/#decimalfield) instead of FloatField on django because it uses Decimal on python and decimal types on postgresql, making sure I don't run into floating point rounding issues.

Also, the documentation on django seems wrong since they say that DecimalField uses REAL for sqlite (https://docs.djangoproject.com/en/3.2/ref/databases/#sqlite-decimal-handling). So, or this doc is wrong or the implementation is wrong, something that I'll also write now on the issue I opened there.