预准备语句的 setBigDecimal 问题?

发布于 2024-12-14 07:02:38 字数 232 浏览 5 评论 0原文

我有一份准备好的声明。我称

stmt.setBigDecimal(BigDecimal.valueOf("0.9"))

问题是数据库中保存的是0.90000000000000000000而不是0.9。

我使用 Microsoft SQL Server JDBC 驱动程序 3.0。

BigDecimal是否不被驱动程序理解或者使驱动程序做错了什么?

I have a prepared statement. I call

stmt.setBigDecimal(BigDecimal.valueOf("0.9"))

the problem is that in the database 0.90000000000000000000 is saved instead of 0.9.

I use Microsoft SQL Server JDBC Driver 3.0.

Is BigDecimal not understood by the driver or make the driver do something wrong?

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

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

发布评论

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

评论(2

留一抹残留的笑 2024-12-21 07:02:38

正如您指出的数据类型是 DECIMAL(36,20),它完全符合逻辑:36,20 表示:36 个数字精度,其中小数分隔符后有 20 个。

如果将 0.9 保存在 DECIMAL(36,20) 中,则它将是 0.90000000000000000000(小数分隔符后有 20 个位置),因为这是该字段的指定精度。

As you indicate that the datatype is DECIMAL(36,20), it is totally logical: 36,20 means: 36 numbers precision, of which there are 20 after the decimal separator.

If you save 0.9 in DECIMAL(36,20), it will be 0.90000000000000000000 (which has 20 positions after the decimal separator) as that is the specified precision for the field.

千笙结 2024-12-21 07:02:38

色谱柱的精度可能是造成这种情况的原因。它很可能被声明为没有特定精度或小数位数的数字。

The precision on the column is likely what is causing this. It is likely it was declared as numeric with no specific precision or scale.

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