Re: Strange round behaviour w/ more than 2 decimals

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

"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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fernando Madruga Pinheiro 2007-07-11 16:39:27 Re: Strange round behaviour w/ more than 2 decimals
Previous Message Peter Wiersig 2007-07-11 15:01:25 Re: Strange round behaviour w/ more than 2 decimals