float value is rounded

Started by Pavel Stehuleabout 16 years ago4 messages
#1Pavel Stehule
pavel.stehule@gmail.com

Hello

I was surprised with rounding relative not big value. Is it correct?

postgres=# select 499188.546875::real;
float4
────────
499189
(1 row)

regards

Pavel Stehule

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#1)
Re: float value is rounded

Pavel Stehule <pavel.stehule@gmail.com> writes:

I was surprised with rounding relative not big value. Is it correct?

You do realize float4 has only 6 decimal digits of precision?

regards, tom lane

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#2)
Re: float value is rounded

2009/11/25 Tom Lane <tgl@sss.pgh.pa.us>:

Pavel Stehule <pavel.stehule@gmail.com> writes:

I was surprised with rounding relative not big value. Is it correct?

You do realize float4 has only 6 decimal digits of precision?

To today I though so float4 is more practical :).

I am smarter now
Pavel

Show quoted text

                       regards, tom lane

#4David Fetter
david@fetter.org
In reply to: Pavel Stehule (#3)
Re: float value is rounded

On Wed, Nov 25, 2009 at 07:46:11PM +0100, Pavel Stehule wrote:

2009/11/25 Tom Lane <tgl@sss.pgh.pa.us>:

Pavel Stehule <pavel.stehule@gmail.com> writes:

I was surprised with rounding relative not big value. Is it
correct?

You do realize float4 has only 6 decimal digits of precision?

To today I though so float4 is more practical :).

Floats have never been safe with respect to operations like =, and
won't become so.

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate