Wednesday, January 8, 2014

Re: DecimalField Problem



On Wednesday, 8 January 2014 16:47:52 UTC, Erik Cederstrand wrote:
Den 08/01/2014 kl. 17.11 skrev Timothy W. Cook <t...@mlhim.org>:

> But one would think that if Django calls it a decimal field, it would convert the float to decimal.
> I suppose I'll do that before writing it out to the file (an XML schema) so it really isn't a big deal, just surprising.

Ah, the "decimal" in DecimalField only refers to how you are supposed to enter the values in a form. Python itself only has float and that's what Django uses internally. Decimal vs. scientific notation is just a matter of how you choose to format the output when converting the float to a string. The default in Python depends on the value:

>>> str(0.1)
'0.1'
>>> str(0.00001)
'1e-05'

No, no, no. None of this is true.

Decimals are not a differently-formatted version of floats. Decimals are not a built-in datatype in Python, it's true, but they are provided in the standard library in (not surprisingly) the `decimal` module. As the documentation for that module explains, decimals do provide precise floating-point arithmetic, and are therefore suitable for representing things like currencies. Databases usually also provide a similar datatype, which Django's DecimalField maps to.
--
DR.

--
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/937a5f48-60e4-498a-bd2c-f34319c81000%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate