本文介绍了Jooq将String转换为BigDecimal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以在jooq查询中将String转换为BigDecimal而又不损失精度?
Is there a way to cast a String to a BigDecimal in a jooq-query without losing precision?
当我执行 endResER.VALUE.cast(BigDecimal.class)时,其中 VALUE 是数据库中具有字符串值的字段,它将返回不带任何小数的BigDecimal数字.
When i do endResER.VALUE.cast(BigDecimal.class) where VALUE is a field with a String-value in the database it returns a BigDecimal without any fraction digits.
我需要比较两个以字符串形式保存在数据库中的金额.
I need to compare two amounts that are saved as Strings in the DB.
推荐答案
您可以像这样将值强制转换为SQLDataType:
You can cast your value to a SQLDataType like this:
endResER.VALUE.cast(SQLDataType.DECIMAL.precision(10, 5))
请注意,jOOQ 3.1存在一个已知问题:#2708 .
Beware though, that there is a known issue for jOOQ 3.1: #2708.
这篇关于Jooq将String转换为BigDecimal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!