﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30290	Documentation should make clear that values on DecimalField is better to be passed as strings	Alexandros Kanterakis	nobody	"On the documentation of [https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.DecimalField DecimalField] it does not mention that passing values as string instead of float has a significant difference. A user that tests the code in the documentation might come to a surprise to find that the following part raises a ValidationError:

{{{
class A(models.Model):
        # A DecimalField as mentioned on the doc
        # ""For example, to store numbers up to 999 with a resolution of 2 decimal places, you’d use:""
	f = models.DecimalField(max_digits=5, decimal_places=2) 
}}}

{{{
A(f=10.1).clean_fields()  # This raises the following exception:
django.core.exceptions.ValidationError: {'f': ['Ensure that there are no more than 2 decimal places.']} 
}}}

If the value of f is passed as string, then it works as expected. 
{{{
A(f=""10.1"").clean_fields() 
}}}

There is a very subtle reference about this on the documentation of the [https://docs.python.org/3/library/decimal.html decimal module]:
{{{
>>> Decimal(3.14)
Decimal('3.140000000000000124344978758017532527446746826171875')
}}}

See also discussion in SO: https://stackoverflow.com/questions/52376693/django-strange-decimalfield-validation
"	Cleanup/optimization	closed	Documentation	2.1	Normal	wontfix			Unreviewed	0	0	0	0	1	0
