I'm using BigDecimal type in Java project. I'm trying to save it using function with numeric field. Java and postgres have different value. E.g. Value of 56.97 from Java saves as 56.9699999999999989 in postgres. How can I prevent it?
If you go to postgresql docs: https://www.postgresql.org/docs/current/datatype-numeric.html
I guess you are using real or double precision which are described as "variable-precision, inexact".
If you want it to be exact, let's say we are talking about money or similar, then you should use numeric
or decimal
types:
NUMERIC(precision, scale)
The precision is the total number of digits, while the scale is the number of digits in the fraction part.
For example, the number 1234.567 has a precision of seven and a scale of three.