pnv
pnv

Reputation: 1499

Data Truncation exception in MySQL for Decimal field

This might seem as a very silly question to many of you. I saw many discussions online regarding this.Still posting it, for getting more clarity on the datatype.

There is a MySQL database maintained for our application. It has a table with a decimal(4,2) field called 'score'. The below statement is giving exception- Data truncation: Out of range value for column 'score' at row 1

      update interaction_events set score=100.0 where id=92;

Decimal(4,2) implies there could be 4 digits where 2 are after the decimal points, have I understood this wrongly?

Could you please help.

Upvotes: 0

Views: 148

Answers (2)

Praveen Prasannan
Praveen Prasannan

Reputation: 7133

Thats right. decimal(4,2) means data can be dd.dd, where d is a digit

Worth a read

Upvotes: 1

Jens
Jens

Reputation: 69515

Your understandig is correct, but if you have a maximum of 4 digits and 2 are after the point you can atleast 2 before the point so if you would like to store 100.0 you have to use a field that is declared as decimal(5,2).

Upvotes: 1

Related Questions