Search code examples
javapostgresqljasper-reports

Jasper not returning proper precision of double Postgres column


I have a query which is creating array of double values returned.

 SELECT array_agg(price) rm FROM product;

When I am running this query in Postgres Shell I am getting output as expected,

-[ RECORD 1 ]--+----------------------
rm             | {79.33,49}

But when I am running the same in Jasper Report I am getting output as

-[ RECORD 1 ]--+----------------------
rm             | {79.3299999999,49}

Is it the issue of Postgres JDBC driver or something is missing my query?


Solution

  • What you need is setting the extra_float_digits PostgreSQL variable to 0 for the connection.

    If you create the connection yourself, you can directly do connection.createStatement().execute("set extra_float_digits to 0")

    If you use a connection pool, you can highjack that validation query to do select set_config('extra_float_digits', '0', false)

    And if none of the above apply, you can do it directly in your query as in select set_config('extra_float_digits', '0', false), array_agg(price) rm from product