1

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,

  1. Decimal can save larger number than Double
  2. Decimal stores exact value and Double store approx. value

So, can anyone explain and maybe give some actual result in query about,

  1. What do they mean by exact value and approx. value?
  2. 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
Bla...
  • 7,228
  • 7
  • 27
  • 46
  • If you can't make it happen now, it doesn't mean that it won't happen in the future. If you stick to DOUBLE, be prepared for rounding errors. – Naktibalda Aug 18 '14 at 08:24
  • There is similar questions here on SO. In terms of monetary operations, check __comments__ to this [answer](http://stackoverflow.com/a/1165788/2637490) - and linked question, such as [this](http://stackoverflow.com/questions/803225/when-should-i-use-double-instead-of-decimal) as well – Alma Do Aug 18 '14 at 08:26
  • 1
    @Naktibalda Well, that's one reason that people keep mentioning, but no one really gives a good example.. – Bla... Aug 18 '14 at 08:29
  • insert something like 0.75 * 0.2 and check (not 0.15 directly) – Thusitha Thilina Dayaratne Aug 18 '14 at 09:22
  • Well, in my case your argument is not valid, check [here](http://sqlfiddle.com/#!2/c81442/1).. If it's wrong approach, then share you fiddle pls. – Bla... Aug 18 '14 at 09:33

0 Answers0