0

I'm trying to divide numbers that are stored in database in millionth, but the decimals are lost.

conditions_set.annotate(
                    _amount_from=ExpressionWrapper(F('amount_from')/1000000, output_field=FloatField()),
                    _amount_to=ExpressionWrapper(F('amount_to')/1000000, output_field=FloatField()),
                    _value=ExpressionWrapper(F('value')/10000, output_field=FloatField())
).values('_amount_from', '_amount_to', '_value').order_by('amount_from')
0 = {dict: 3} {'_amount_from': 0.0, '_amount_to': 1000.0, '_value': 0.0}
1 = {dict: 3} {'_amount_from': 1000.0, '_amount_to': 3000.0, '_value': 0.0}

Amount from of key 1 is equal to 1000001, so I'm expecting that the result of 1000010000 / 1000000 is 1.000,01. As the 'value' is equal to 6800, I'm expecting that the result of 6800/10000 is 0,68. But I get 0.0.

  • 1
    Try `F('value')/10000.0` – Olvin Roght Jan 11 '22 at 10:19
  • Does this answer your question? [Django, division between two annotate result won't calculate correctly](https://stackoverflow.com/questions/32262862/django-division-between-two-annotate-result-wont-calculate-correctly) – Olvin Roght Jan 11 '22 at 10:21

0 Answers0