0
我有一個針對MySql數據庫運行的Spring應用程序。我有一個銷售表所示:春季queryForLong - 精度損失
+-------------------+------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+------------------------------+------+-----+---------+-------+
| Price | decimal(19,4) | NO | | NULL | |
| ItemId | int(10) unsigned | NO | | NULL | |
+-------------------+------------------------------+------+-----+---------+-------+
在我的Spring類,我有以下幾點:
long price = getSimpleJdbcTemplate().queryForLong("SELECT price FROM sales WHERE itemID = :itemID", params);
logger.info("price: " + price + ");
然而,這回爲1的價格,即使該查詢直接對數據庫返回0.8500。我該如何避免從數據庫中的小數點到精確的丟失精度?