2005 年和 2000 年的 SQL 舍入问题

发布于 2024-08-28 18:33:02 字数 198 浏览 5 评论 0原文

我在数据库中有一个值为 2.700000002。当我在 SQL SERVER 2005 的 Management studio 中运行查询时,我得到 2.7。但是当我在 SQL SERVER 2000 查询分析器中运行时,它出现 2.700000002。

2.70000002 是正确的,为什么 SQL SERVER 2005 尝试通过舍入或选择下限值来更改该值?

I have a value in the database which is 2.700000002. When I run a query in Management studio in SQL SERVER 2005 I get 2.7. But when I run in SQL SERVER 2000 query analyzer it comes 2.700000002.

2.70000002 is correct why is SQL SERVER 2005 trying to change the value by rounding it or selecting the floor value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

自由如风 2024-09-04 18:33:02

完全相同的目标服务器、数据库、数据类型、处理器、架构等?

如果没有,这只是工具显示近似浮点值的方式

Exactly the same target server, database, datatype, processor, architecture etc?

If not, it's simply how the tools will display an approximate float value

左岸枫 2024-09-04 18:33:02

大多数事情都会对数字进行四舍五入以显示。

~$ ghci
Prelude> 2.7
2.7
~$ irb
>> 2.7
=> 2.7
~$ python
>>> 2.7
2.7000000000000002

对于交互式使用,这通常已经足够了——唯一能看到查询分析器的人就是你,那么为什么这很重要呢?对于实际显示,您无论如何都应该指定格式。如果您确实需要 "2.7" 的精确值,那么无论如何您都应该使用十进制类型,正如无数文章和答案可以告诉您的那样。

Most things round off numbers for display.

~$ ghci
Prelude> 2.7
2.7
~$ irb
>> 2.7
=> 2.7
~$ python
>>> 2.7
2.7000000000000002

For interactive use, this is usually good enough — the only person to see the query analyzer is you, so why does it matter? For actual display, you should specify a format anyway. If you really need the exact value of "2.7", then you should be using a decimal type anyway, as countless articles and answers can tell you.

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