Re: precision of numeric type - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: precision of numeric type
Date
Msg-id 3DBEBD04.7000503@xythos.com
Whole thread Raw
In response to precision of numeric type  ("w.winter" <w.winter@logitags.com>)
List pgsql-jdbc
Wolfgang,


w.winter wrote:
> Hi,
>
> on testing our auto-configuration persistence framework ACP against
> PostgreSQL we found the following problem:
>
> I have a table with a column of type numeric(48,10). The PostgreSQL docs
> say: "The type numeric can store numbers of practically unlimited size and
> precision, while being able to store all numbers and carry out all
> calculations exactly."

This is true.

>
> I store the Double value 1212121234.5634349876 with a
> PreparedStatement.setDouble()
>

But the problem is that java Double isn't able to perform calculations
exactly.  If you want exact precision you should be using the BigDecimal
datatype (and getBigDecimal/setBigDecimal).  BigDecimal is the logical
java data type that corresponds to the numeric type in postgres.

thanks,
--Barry




pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: executeBatch problem
Next
From: Barry Lind
Date:
Subject: Re: DatabaseMetaData.getTables() problem