Search code examples
mysqldecimalsqldatatypes

Price changes when using decimal data type


I have a column with the data type decimal setup as so..

`cost` decimal(4,2) NOT NULL DEFAULT '0.00',

However when I input a price, say 100.00, next time I look at it it says 99.99.

Why is this? I thought 4,2 allowed 4 chars before the decimal & 2 after?


Solution

  • 4 is the precision (total number of digits), 2 is the scale (decimal places).

    In your case you want 6,2.