Float8 precision problem

Started by Hengki Suhartoyoover 19 years ago4 messagesgeneral
Jump to latest
#1Hengki Suhartoyo
hengman03@yahoo.com

Hi all,

I got problem in postgrsql 8.0 when subtraction in float8, this is my query :
select 6.1::float8-6::float8

Result>>> 0.099999999999996

I need the result like natural subtraction is 0.1

Help me please....

____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

#2Dann Corbit
DCorbit@connx.com
In reply to: Hengki Suhartoyo (#1)
Re: Float8 precision problem

And (indeed) that is exactly the answer that you received [within
DLB_DIG units of precision].

I guess that you will be happier with NUMERIC(precision, scale) because
the results of operations will be closer to what you expect.

Suggested reading:
http://www.physics.ohio-state.edu/~dws/grouplinks/floating_point_math.pd
f

________________________________________
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Hengki
Suhartoyo
Sent: Thursday, November 30, 2006 2:56 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Float8 precision problem

Hi all,

I got problem in postgrsql 8.0 when subtraction in float8, this is my
query :
select 6.1::float8-6::float8

Result>>> 0.099999999999996

I need the result like natural subtraction is 0.1

Help me please....

________________________________________
Want to start your own business? Learn how on Yahoo! Small Business.

#3Kaloyan Iliev Iliev
news1@faith.digsys.bg
In reply to: Hengki Suhartoyo (#1)
Re: Float8 precision problem

Hi,

What about cast to numeric?

select 6.1::numeric-6::numeric ;
?column?
----------
0.1
(1 row)

Regards,
Kaloyan Iliev

Hengki Suhartoyo wrote:

Show quoted text

Hi all,

I got problem in postgrsql 8.0 when subtraction in float8, this is my
query :
select 6.1::float8-6::float8

Result>>> 0.099999999999996

I need the result like natural subtraction is 0.1

Help me please....

------------------------------------------------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.
<http://us.rd.yahoo.com/evt=41244/*http://smallbusiness.yahoo.com/r-index&gt;

#4Michael Glaesemann
grzm@seespotcode.net
In reply to: Hengki Suhartoyo (#1)
Re: Float8 precision problem

On Nov 30, 2006, at 19:56 , Hengki Suhartoyo wrote:

I got problem in postgrsql 8.0 when subtraction in float8, this is
my query :
select 6.1::float8-6::float8

Result>>> 0.099999999999996

I need the result like natural subtraction is 0.1

Then use numeric instead of float. Float by its very nature is not
precise.

Michael Glaesemann
grzm seespotcode net