Monday, September 5, 2011

DecimalField values changing on save()

Hi all

I know this is a bit of a corner case, but I was slightly surprised by
the behaviour of DecimalField with the value -0.0. Given the model:

class Word(models.Model):
word = models.CharField(max_length=50, unique=True)
number = models.DecimalField(max_digits=8, decimal_places=5)

def __unicode__(self):
return self.word


I then get the following behaviour:


> python2.7 manage.py shell

In [1]: from vortaro.models import Word

In [2]: from decimal import Decimal

In [3]: word = Word(word='foo', number=Decimal('-0.0'))

In [4]: word.save()

In [6]: word_from_db = Word.objects.get()

In [7]: word_from_db.number
Out[7]: Decimal('0')

In [8]: word.number
Out[8]: Decimal('-0.0')

Is it supposed to behave like this?

Cheers
Wilfred

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment