Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 1FAB1632921 for ; Fri, 25 Jun 2010 20:26:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 58854-06 for ; Fri, 25 Jun 2010 23:25:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f174.google.com (mail-px0-f174.google.com [209.85.212.174]) by mail.postgresql.org (Postfix) with ESMTP id 65A296328BA for ; Fri, 25 Jun 2010 20:25:51 -0300 (ADT) Received: by pxi8 with SMTP id 8so926613pxi.19 for ; Fri, 25 Jun 2010 16:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=7FyHiu1VK7IYdZkiA5VM6/tZQJ9bValJPVCr5IkFIls=; b=W9yvUGENtyh8xOVXyGEb5tcwaYb+kcpahkmuaMyN+7XJwS0gGhY4tgf3tkTh3ZDxAp /1gxOJujvsGlfl9+t7UGOzLxDjXlECUctMoLayvK2NL9Q21DruTHvCtz9TNABTuph03S KxeqQ7vfvm03MXOfeNZK+SdaOeS7Xxd0ViqIU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=s9yQHtXgihG/jt47sPMVzdURtFKER70ft5TkZ//S2oRPlSlfgS3qPFmhtdtE3QTjDA /Hwl97G9BmApuagf8mYlqrTdeoIlgBAvHQuuL5rHGXUK7+kIYmBnpVznPNIH5wah5p9p acJJrXUQeoAjIrrXfVtET7KNBSGWq+zVuzXk8= Received: by 10.142.1.22 with SMTP id 22mr1856442wfa.345.1277508349530; Fri, 25 Jun 2010 16:25:49 -0700 (PDT) Received: from tucker.local (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id o38sm1039565rvp.17.2010.06.25.16.25.48 (version=SSLv3 cipher=RC4-MD5); Fri, 25 Jun 2010 16:25:49 -0700 (PDT) From: Adrian Klaver Reply-To: adrian.klaver@gmail.com To: pgsql-sql@postgresql.org Subject: Re: Round integer division Date: Fri, 25 Jun 2010 16:25:48 -0700 User-Agent: KMail/1.9.10 Cc: Lee Hachadoorian References: <4C25334D.4040805@gmail.com> In-Reply-To: <4C25334D.4040805@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201006251625.48231.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-5 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201006/99 X-Sequence-Number: 34290 On Friday 25 June 2010 3:53:01 pm Lee Hachadoorian wrote: > Is it documented anywhere that floating-point numbers round > "scientifically", that is 0.5 rounds to the nearest even number? Compare: > > SELECT round(2.5::real), round(2.5::numeric), round(3.5::real), > round(3.5::numeric); > > generates > > 2 | 3 | 4 | 4 > > I stumbled across this when I was trying to use round(a::real/b::real) > to generate a rounded result to dividing integers, and noticed sometimes > 0.5 was truncated and sometimes it was rounded up. Couldn't find > anything about this in the archives or the data type documentation. Is > there something obvious that I'm I missing? > > Thanks, > > -- > > Lee Hachadoorian > PhD Student, Geography > Program in Earth & Environmental Sciences > CUNY Graduate Center See here for explanation: http://archives.postgresql.org/pgsql-general/2010-03/msg00969.php -- Adrian Klaver adrian.klaver@gmail.com