I've got a set of stored procedures which do a set of calculations, however I seem to be losing precision when using decimal types.
I'm expecting 0.0493318673793 for the calculation below - instead I'm getting 0.049331. I've tested out different data types, and the accuracy I'm after I'm only getting when using floats (which I've read should be avoided).
--Representative of SP
SELECT CAST(4000000.00 AS MONEY)/CAST(81083490.50 AS DECIMAL(34,26))
--0.049331
--Using greater decimal precision
SELECT CAST(4000000.00 AS MONEY)/CAST(81083490.50 AS DECIMAL(38,16))
--0.0493318
--Using Float
SELECT CAST(4000000.00 AS MONEY)/CAST(81083490.50 AS FLOAT)
--0.0493318673793403
Are floats really that bad? If so, what alternatives do I have?
Exploring on Hamlets note below. Why do the following below provide different outputs?
SELECT CAST(4000000.00 AS MONEY)/CAST(81083490.50 AS DECIMAL(38,16))
--0.0493318
SELECT CAST(4000000.00 AS MONEY)/CAST(81083490.50 AS DECIMAL(38,3))
--0.04933186737934031096