Well, I know this question has been asked several times.. But, I still don't get a satisfied explanation, especially on why we MUST use Decimal
for monetary purpose.. As far as I know,
Decimal
can save larger number thanDouble
Decimal
stores exact value andDouble
store approx. value
So, can anyone explain and maybe give some actual result in query about,
- What do they mean by exact value and approx. value?
- Why should I use
Decimal
for monetary purpose ?
Currently I'm using Double(15,2)
as it gives enough precision for my boss. Besides I ran some test in this SQLFiddle and I don't see any precision issue..
TESTED QUERY:
create table test(
value1 Decimal(15,4),
value2 Double(15,4)
);
insert into test values(0.0001, 0.0001),
(123.123, 123.123),
(0.0000001, 0.0000001);
select sum(value1), sum(value2) from test
RESULT
SUM(VALUE1) SUM(VALUE2)
123.1231 123.1231