You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Django's DecimalField may be confusing for data inputters. It validates decimal places and digits before min and max values (added as separate validators) and the error may be confusing for users.
It would be better to have a field that converts the input to Decimal and then checks whether it is betwen max and min values, truncating the exceeding precision.
I.e, DecimalField(max_digits=5, decimal_places=3) has an implicit max value of 99.999 and min of -99.999. If validators=[MinValueValidator(2.0), MaxValueValidator(8.0)], the values 104.5, 80.3444, 2.1234, -999 would rise a "check the digits" or "invalid value" errors.
Taking into account the DRF implementation of DecimalField, it would be simpler and better if the field quantizes the input to the desired precision and checks if it is between max and min. Then for 104.5 it would say "value larger than max", 80.3444: "value larger than max", for 2.1234 it would store 2.123 (selecting rounding), and for -999 would say "value smaller than min".
This may require adjust the field mapping of DRF (check).
The text was updated successfully, but these errors were encountered:
Django's DecimalField may be confusing for data inputters. It validates decimal places and digits before min and max values (added as separate validators) and the error may be confusing for users.
It would be better to have a field that converts the input to Decimal and then checks whether it is betwen max and min values, truncating the exceeding precision.
I.e,
DecimalField(max_digits=5, decimal_places=3)
has an implicit max value of 99.999 and min of -99.999. Ifvalidators=[MinValueValidator(2.0), MaxValueValidator(8.0)]
, the values 104.5, 80.3444, 2.1234, -999 would rise a "check the digits" or "invalid value" errors.Taking into account the DRF implementation of DecimalField, it would be simpler and better if the field quantizes the input to the desired precision and checks if it is between max and min. Then for 104.5 it would say "value larger than max", 80.3444: "value larger than max", for 2.1234 it would store 2.123 (selecting rounding), and for -999 would say "value smaller than min".
This may require adjust the field mapping of DRF (check).
The text was updated successfully, but these errors were encountered: