I have a model {{{MyModel}}} that has a field {{{foo}}} with
{{{max_digits=10}}} and {{{decimal_places=2}}}, so when I save a value
3.4211 (passed as a common float) the value stored is Decimal("3.42").
However, if call {{{MyModel._meta.get_field("foo").to_python(3.4211)}}}
the result is Decimal("3.421100000").
Inspecting the source code of this method {{{to_python}}} I guess the
problem is that it uses decimal.Context with {{{prec}}} equal to the
number of {{{max_digits}}}, which is something that only makes sense if
the number passed has {{{max_digits}}} meaningful digits.
Should it be changed to return the decimal with the specified number of
digits, or am I wrong assuming that {{{to_python}}} should return the
exact same value that will be stored?
--
Ticket URL: <https://code.djangoproject.com/ticket/32761>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #26459.
--
Ticket URL: <https://code.djangoproject.com/ticket/32761#comment:1>