views:

64

answers:

3

Does the SQL Server decimal data type stored the actual number of digits after the decimal for each value in a column?

For example

UPDATE [Mixes] SET [Concentration] = 0.0012500 WHERE [Id] = 1

where

Concentration Decimal(21,11)

Is it possible to retrieve the exact "0.0012500" value as entered by the user, or is it necessary to store the actual number of decimal places entered in another column?

+1  A: 

You'd have to store the number of decimals separately.

Jonas Lincoln
+2  A: 

The decimal type stores the numeric value up to the precision specified. It does not store formatting. It's like saving an int with leading zeros. The leading zeros don't change the numeric value. If the user-entered format is needed, you'll need to store that separately or store the number as a varchar.

DyingCactus
+1  A: 

You would not be able to tell the difference between 0.0012500 and 0.00125 after it was entered just using a decimal column. You would need to store in a textual form or parse the information about how it was entered and store that information.

Cade Roux