Store and return decimals with user-entered precision in SQL Server
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] = 开发者_Python百科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?
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.
You'd have to store the number of decimals separately.
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.
精彩评论