I am working on building an application for a banking institution where the accuracy for monetary transaction is very much essential. I am thinking of using the datatype Money in SQL Server.
So I need suggestion whether the datatype I am using is enough to provide accuracy or not? I also wanted to know which one if better if i use the numeric datatype or Money datatype?
Thanks in advance
A quick search in the SQL Server Books Online would have revealed….
The money and smallmoney data types are accurate to a ten-thousandth of the monetary units that they represent. (that’s four digits after the decimal point)
Numeric data types that have fixed precision and scale.
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.
p (precision)
The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.
s (scale)
The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.
Numeric(orDecimalwhich is the same) certainly has the larger range – and you can tweak how many digits you need before or after the decimal point.On the other hand – even
Moneyis accurate to one tenth of a thousandth of dollars or Euros or whatever currency you’re interested in – that’s typically enough even for a bank….So basically:
if you need more than 4 significant digits after the decimal point, or more than 15 digits before the decimal point – pick
NUMERIC/DECIMALotherwise,
MONEYwill be just fine