RE: [ADMIN] float4

From: JT Kirkpatrick <jt-kirkpatrick(at)mpsllc(dot)com>
To: "'Don Garrett'" <garrett(at)bgb-consulting(dot)com>
Cc: "'pgsql-interfaces(at)hub(dot)org'" <pgsql-interfaces(at)hub(dot)org>
Subject: RE: [ADMIN] float4
Date: 1999-06-28 20:53:28
Message-ID: 01BEC186.BFA829C0.jt-kirkpatrick@mpsllc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

ouch. hard to think of dollars only when you are paying vendors,
technicians, billing customers, etc. surely i won't have to make an int
field for the dollars and an int field for the cents!!! the money field
would work nicely if the odbc driver would handle it correctly!

i forwarded this to the odbc list -- any idea why a money field can't be
used from msaccess97 through the odbc??

thanks for your help!

jt

-----Original Message-----
From: Don Garrett [SMTP:garrett(at)bgb-consulting(dot)com]
Sent: Monday, June 28, 1999 4:25 PM
To: JT Kirkpatrick
Subject: Re: [ADMIN] float4

You shouldn't use a float at all for exact amounts. Floats handle
arbitrary precision, but do it rounding off values somewhat. The way the
round off works is based on the (base 2) internal representation and so
it never quite seems to make sense in decimal. It's possible on some
machines/float formats to have "if (1.0 + 1.0 = 2.0)" evaluate to false.

When I first started programming, I did a very simple custom
accounting package using floats.... and had to go back and rewrite all
of it.

You will do better to use integers (no rounding at all) and consider
the contents to be the number of pennies involved, not dollars.

JT Kirkpatrick wrote:
>
> we have a database (linux, 6.4.2, new odbc, connections from msaccess /
> win98) -- access doesn't fully appreciate the monetary type in postgres,
so
> we made all monetary fields FLOAT4's. weird stuff -- or maybe not to you
> -- we insert 23516.69 into a float4 field directly in psql, and then
select
> it, and it shows 23516.7. this is not good for a field used for MONEY!!!
> what are the limitations of float4? should i have used float8?
>
> thanks for any help you can offer. . .
>
> jt

--
Don Garrett dgarrett(at)acm(dot)org
BGB Consulting http://www.bgb-consulting.com/garrett

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Don Garrett 1999-06-28 21:06:51 Re: [ADMIN] float4
Previous Message Tommy 1999-06-28 15:32:31 postgres odbc driver