Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 201C7632D8B for ; Thu, 14 May 2009 14:04:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 33141-08 for ; Thu, 14 May 2009 14:04:45 -0300 (ADT) X-Greylist: delayed 00:23:45.224867 by SQLgrey-1.7.6 Received: from mail.mnc.ch (62-2-77-205.static.cablecom.ch [62.2.77.205]) by mail.postgresql.org (Postfix) with ESMTP id BB6376325A1 for ; Thu, 14 May 2009 14:04:46 -0300 (ADT) Received: from localhost (mail2.mnc.ch [127.0.0.1]) by mail.mnc.ch (Postfix) with ESMTP id BAB5A2308F; Thu, 14 May 2009 16:40:59 +0000 (GMT) X-Virus-Scanned: amavisd-new at mnc.ch Received: from mail.mnc.ch ([127.0.0.1]) by localhost (mail2.mnc.ch [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id J85iSv32nldm; Thu, 14 May 2009 16:40:59 +0000 (GMT) Received: from meuh.localdomain (62-2-77-204.static.cablecom.ch [62.2.77.204]) by mail.mnc.ch (Postfix) with ESMTP id 175052308D; Thu, 14 May 2009 16:40:59 +0000 (GMT) Received: by meuh.localdomain (Postfix, from userid 1000) id 1901DDF2A7; Thu, 14 May 2009 18:40:57 +0200 (CEST) To: Tanel Cc: pgsql-jdbc@postgresql.org Subject: Re: ResultSet getString() result differs in 8.3 jdbc (compared to 8.1), with "real" type References: <23536933.post@talk.nabble.com> From: Guillaume Cottenceau X-Hashcash: 1:20:090514:tanel.ehrenpreis@finestmedia.ee::rt073Dzk6Sl4M6Iv:00000000000000000000000000000048Ep X-Hashcash: 1:20:090514:pgsql-jdbc@postgresql.org::ApFW736zicavsW0q:0000000000000000000000000000000000006OgL Date: Thu, 14 May 2009 18:40:56 +0200 In-Reply-To: <23536933.post@talk.nabble.com> (Tanel's message of "Thu\, 14 May 2009 02\:10\:45 -0700 \(PDT\)") Message-ID: <87y6szvdrb.fsf@meuh.mnc.lan> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/79 X-Sequence-Number: 19629 Tanel writes: > Hi, > > I made some searches also, however found nothing exactly related to this > problem. We just shifted from using 8.1 driver to 8.3 however seems that 8.3 > driver handles differently Postgresql floating type values, when using > org.postgresql.jdbc2.AbstractJdbc2ResultSet.java getString() on them ? > For example, when there is "real" type value 20.7 in database and we try to > get it through getString() then old 8.1 driver returns nicely 20.7, but new > 8.3 driver is returning something like 20.700001. Wanting to manipulate precise decimal values with float or double datatypes is bound to fail, because the binary representation of values make it impossible - it holds the mantissa and the exponent, so some rounding must happen. The "display" will depend on rounding and so forth. 20.7 doesn't exist "as such" in the computer, when using float or double datatypes. If you want to manipulate precise decimal numbers, use the SQL NUMERIC data type (BigDecimal in java); or else, you can always use "fixed point" numbers, e.g. if you need a monetary value you may store cent values as an integer (2070 in database to represent $20.7) and shift by 100 only for user interfacing. Beside, getString() on a floating type value is just wrong, but you guessed it already! :) -- Guillaume Cottenceau