Brett
Brett

Reputation: 20049

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?

Upvotes: 1

Views: 545

Answers (3)

Wops
Wops

Reputation: 993

decimal [ (p[ ,s] )] and numeric[ (p[ ,s] )] Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). numeric is functionally equivalent to decimal.

BOTTOM LINE: you should try and make it 6,2.

6 as in total 6 digits, 2 as in 2 digits after the point.

Upvotes: 1

xdazz
xdazz

Reputation: 160883

A DECIMAL(M,D) column permits at most M - D digits to the left of the decimal point.

M is the maximum number of digits (the precision).

Upvotes: 1

Mitch Satchwell
Mitch Satchwell

Reputation: 4830

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

In your case you want 6,2.

Upvotes: 1

Related Questions