Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql double length error

Tags:

mysql

I want do column for percents..
I need write: 1.00, 2.00, 99.99, 100.. %
How I can use double type for this?

Now I have:

Double(4,2)

But when I write 100 in column I get error:

Numeric value out of range: 1264 Out of range value for column

like image 534
Dumitru Avatar asked Oct 24 '25 18:10

Dumitru


1 Answers

Look at the answer here (doubleand decimal have the same syntax) or the MySQL manual:

DOUBLE[(M,D)]

M is the total number of digits and D is the number of digits following the decimal point. If M and D are omitted, values are stored to the limits permitted by the hardware. A double-precision floating-point number is accurate to approximately 15 decimal places.

In short, DOUBLE(4,2) means at most 4 digits, with 2 digits after the decimal point. So to support two digits decimals until 100, you need:

double(5,2) unsigned

Note that the unsigned is not mandatory, but can be more performant and safe if you know you won't need negative values.

like image 85
Derlin Avatar answered Oct 26 '25 09:10

Derlin