Should I use numeric or float to avoid calculaton prolems in PostgreSQL

删除回忆录丶 提交于 2020-05-14 14:29:39

问题


I have encountered a topic regarding to calculation errors on Accuracy problems.

I end up with the following values in one of my queries in PostgreSQL:

1.0752688172043 (when using float)
1.07526881720430110000 (when using numeric)

1) So, for these values I think I should use numeric data type in order to obtain result more accurately. Is that right?

2) What if the following values (assume that the rest digits after the last number is 0). In that case should I still use numeric rather than float?

1.0752688172043 (when using float)
1.07526881720430000000 (when using numeric)

3) What about extra 0's when using numeric? For example, if the result is 0, it displays 0 with lots of digits instead of single digit. In that case is there a format for displaying single 0 in numeric results?

来源:https://stackoverflow.com/questions/61711547/should-i-use-numeric-or-float-to-avoid-calculaton-prolems-in-postgresql

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