Ali
Ali

Reputation: 267317

Strange ' Data truncation: Out of range value' error for Decimal column

I have a column foo in a mysql table, which is of the type DECIMAL (10,10).

If I try to insert a record in it with the value of foo as 100.0, that produces the error ' Data truncation: Out of range value for column 'foo' at row 1`

What am I doing wrong - doesn't 10,10 means upto 10 digits both before and after the decimal point, which should allow for this number?

Upvotes: 1

Views: 1948

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133410

If you want 10 digit and 10 decimal the you need

DECIMAL (20,10)

The first value define the total number of digit .. the secondo the max digit after the decimal point

Upvotes: 2

Bernd Buffen
Bernd Buffen

Reputation: 15057

No, the first value means the total digits, and the second means the digits after the comma,

so,

20,10 = 20 Digits and 10 after comma => 10, before and ten after

A packed "exact" fixed-point number. M is the total number of digits (the precision) and D is the number of digits after the decimal point (the scale). The decimal point and (for negative numbers) the "-" sign are not counted in M. If D is 0, values have no decimal point or fractional part and on INSERT the value will be rounded to the nearest DECIMAL. The maximum number of digits (M) for DECIMAL is 65. The maximum number of supported decimals (D) is 30. If D is omitted, the default is 0. If M is omitted, the default is 10.

Upvotes: 4

Related Questions