Re: Strange round behaviour w/ more than 2 decimals

From: "Fernando Madruga Pinheiro" <fernando(dot)madrugapinheiro(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Strange round behaviour w/ more than 2 decimals
Date: 2007-07-11 16:39:27
Message-ID: 979602370707110939u5f719170r3ac48a8623d3c803@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Tom,

Sorry. After sending to group one friend of mine explained to me how round
works -- not postgresql round, but round in math.
I do not know any software that would produce that output.

I thought that when 1.8947 was rounded to 2 decimal places, 7 would round-up
4, then "5" would round-up 9.

Reading http://www.ai.com.br/pessoal/indices/2A1A.HTM show the correct way
(sorry, the page is in brazilian portuguese).

Anyway, the document shows: DO NOT DO RECURSIVE ROUNDS! hehe.

Thanks for the answer and sorry for the incorrect question.

Regards,
Fernando Pinheiro

2007/7/11, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
> "Fernando Madruga Pinheiro" <fernando(dot)madrugapinheiro(at)gmail(dot)com> writes:
> > If I use ROUND(1.8947, 2), it should return 1.90, but it does return
> 1.89.
>
> Why do you consider that wrong? It's the closest approximation.
> Do you know of any other software that would produce 1.90 from a
> similar query?
>
> > Rounding to 3 decimal places, then 2 (eg.: ROUND(ROUND(1.8947, 3), 2) )
> then
> > I get 1.90!
>
> Since ROUND() is a lossy process by definition, you cannot expect
> that different multi-step paths will always yield the same result.
>
> regards, tom lane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message marcelo Cortez 2007-07-11 16:41:03 troubble with contrib compile
Previous Message Tom Lane 2007-07-11 15:07:40 Re: Strange round behaviour w/ more than 2 decimals