Re: DecimalField Problem
On Wed, 8 Jan 2014 16:44:56 +0100, Erik Cederstrand
<erik+lists@cederstrand.dk> declaimed the following:
>Den 08/01/2014 kl. 16.18 skrev Timothy W. Cook <tim@mlhim.org>:
>
>> I have several decimal fields defined in the model like this:
>>
>> min_inclusive = models.DecimalField(_('minimum inclusive'), max_digits=19, decimal_places=10, help_text=_("Enter the minimum (inclusive) value for this concept."), null=True, blank=True)
>>
>> Via the admin interface when I enter a 0 (zero) and save the object I get 0E-10 as the value. I am using PostgreSQL 9.1 for persistence.
>>
>> So, why doesn't it just store a zero?
>
>Underneath a DecimalField there is a Python float type, and some equivalent float type in your database. Float values are an approximation, so 0.000000000000 and 0 are not guaranteed to be equal. See http://stackoverflow.com/questions/2986150/python-floating-number
>
If Django's "DecimalField" is NOT use Python's Decimal type, I'd be
concerned... Python's Decimal is NOT a "float".
However, the conversion of a Decimal to/from PostgreSQL might result in
a floating point value -- which I'd consider a flaw in the database adapter
as PostgreSQL does have a NUMERIC data type that should map directly to
Python Decimal.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/omrrc9pfq5ds915ond5ice96qi8tpudska%404ax.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home