在 SQL Server 中存储和返回具有用户输入精度的小数

发布于 2024-08-17 04:55:34 字数 286 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哀由 2024-08-24 04:55:34

小数类型存储高达指定精度的数值。它不存储格式。这就像保存一个带有前导零的 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.

凉宸 2024-08-24 04:55:34

您必须单独存储小数位数。

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

﹂绝世的画 2024-08-24 04:55:34

仅使用小数列输入后,您将无法区分 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文