Hibernate loss of precision in results when mapping a number (22,21) to BigDecimal

眉间皱痕 提交于 2019-12-01 06:01:25
axtavt

It's a result of initializing BigDecimal from double:

System.out.println(String.format("%21.20f", new BigDecimal(0.493)); 
// Prints 0,49299999999999999378  

So, when BigDecimal initialized this way is saved in the database, it produces an inaccurate value, which is correctly loaded later.

If BigDecimal is initialized by string or if the value is set directly in Java everything works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!