views:

1072

answers:

5

I need to store a couple of money related fields in the database but I'm not sure which data type to use between money and decimal.

+3  A: 

I guess it comes down to precision and scale. IIRC, money is 4dp. If that is fine, money expresses your intent. If you want more control, use decimal with a specific precision and scale.

Marc Gravell
+4  A: 

I always use Decimal; never used MONEY before.

Recently, I found an article regarding decimal versus money data type in Sql server that you might find interesting:

Money vs Decimal

It also seems that the money datatype does not always result in accurate results when you perform calculations with it : click

What I've done as wel in the past, is using an INT field, and store the amount in cents (eurocent / dollarcent).

Frederik Gheysels
+8  A: 

Decimal and money ought to be pretty reliable. What i can assure you (from painful personal experience from inherited applications) is DO NOT use float!

Conrad
Why not? What problems did you have using float?
Matt Hamilton
Rounding errors most probably
nalply
His application probably totalled up a few 200,000 amounts and ran out of digits
Chris S
Floats cause very subtle rounding errors especially when doing calculations with lots of numbers. For financial applications this causes numbers not to balance
Conrad
+1  A: 

It depends on your application!!! I work in financial services where we normally consider price to be significant to 5 decimal places after the point, which of course when you buy a couple of million at 3.12345pence/cents is a significant amount. Some applications will supply their own sql type to handle this.

On the other hand, this might not be necessary. <Humour> Contractor rates always seemed to be rounded to the nearest £100, but currently seem to be to nearest £25 pounds in the current credit crunch. </Humour>

AlSki
A: 

Use decimal and use more decimal places than you think you will need so that caclulations will be correct. Money does not alwys return correct results in calculations. Under no circumstances use float or real as these are inexact datatypes and can cause calculations to be wrong (especially as they get more complex).

HLGEM