在 SQL Server 中存储和返回具有用户输入精度的小数
SQL Server decimal
数据类型是否存储列中每个值的小数点后的实际位数?
例如,
UPDATE [Mixes] SET [Concentration] = 0.0012500 WHERE [Id] = 1
是否
Concentration Decimal(21,11)
可以检索用户输入的确切“0.0012500”值,或者是否有必要存储在另一列中输入的实际小数位数?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
小数类型存储高达指定精度的数值。它不存储格式。这就像保存一个带有前导零的 int 。前导零不会更改数值。如果需要用户输入的格式,则需要单独存储该格式或将数字存储为 varchar。
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.
仅使用小数列输入后,您将无法区分 0.0012500 和 0.00125 之间的差异。您需要以文本形式存储或解析有关如何输入的信息并存储该信息。
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.