Skip to content
Advertisement

How does Django save decimal values?

What am I doing wrong?

JavaScript

I do something like that:

JavaScript

count is the sum of all ratings of given MyModel and votes is an array of those ratings, their division gives an average rating for MyModel (sorry if I described it incorrectly due to my poor English).

If i change previous to:

JavaScript

Then ‘anything’ ends up in the database, but rating does not.

Why? am I using wrong field type?

Alan.

Advertisement

Answer

max_digits is a number of digits before and after the decimal point. With your settings it allows you to store numbers between 0.00 and 0.99. Is it right? I can not figure out the range of values for average variable.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement