预准备语句的 setBigDecimal 问题?
我有一份准备好的声明。我称
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您指出的数据类型是 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.
色谱柱的精度可能是造成这种情况的原因。它很可能被声明为没有特定精度或小数位数的数字。
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.