Linh Nguyen
Linh Nguyen

Reputation: 3880

Django DecimalField what is the maximum value of max_digits?

Hi i'm trying to design my model which contain a field that supposed to store a really big integer number. Why is it big ? because when the front end send the data up to the server, the float number get converted into integer (for example: 2.44444444 will get converted to 244444444).

The database i'm using is MySql

Reading through the Django model fields docs i see that bigintegerfield only support up to 9223372036854775807 which is 19 digits(64 bits). I'm afraid that won't be enough so i think i should use DecimalField since it support max_digits like so:

DecimalField(max_digits=40, decimal_places=0, default=0) #it will act like an integer because decimal_place=0

But i don't know how what the maximum value of max_digits since it don't seems to be mentioning about it in the docs and i still can't find any informations about it after googling

If anyone know what the maximum amount max_digits in DecimalFields, it would be a great help.

Upvotes: 2

Views: 4472

Answers (2)

Codertjay
Codertjay

Reputation: 997

max_digits must be equal, or higher than decimal_places.

If you were to have 123456.654321 you'd have to define max_digits=12, decimal_places=6.

max_digits is INCLUDING decimal_places.

Upvotes: 3

Selcuk
Selcuk

Reputation: 59174

If you are using MySQL, the maximum number of digits is 65. The number of digits to the right of the decimal point can be up to 30:

https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html

For PostgreSQL, it is up to 131072 digits before the decimal point and up to 16383 digits after the decimal point:

https://www.postgresql.org/docs/10/datatype-numeric.html

SQLite has no real decimal internal type.

Upvotes: 3

Related Questions