Thread: RE: [ADMIN] float4

RE: [ADMIN] float4

From
JT Kirkpatrick
Date:
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@bgb-consulting.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@acm.org
BGB Consulting                  http://www.bgb-consulting.com/garrett



Re: [ADMIN] float4

From
Don Garrett
Date:
  No, use one field for both. But use the UNIT pennies. To get the
number of dollars, divide by 100, to get the number of pennies (without
dollars) do (value  % 100).
 You can use the single value for additions, subtractions, totals and
everything else, just as if it were type money. In fact, this is
probably how type money stores things internally.
 And no, I don't know anything about ODBC, so I have no idea why you
are having trouble with the money type.

JT Kirkpatrick wrote:
> 
> 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@bgb-consulting.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@acm.org
> BGB Consulting                  http://www.bgb-consulting.com/garrett

--
Don Garrett                                          dgarrett@acm.org
BGB Consulting                  http://www.bgb-consulting.com/garrett


Re: [INTERFACES] RE: [ADMIN] float4

From
Herouth Maoz
Date:
At 23:53 +0300 on 28/06/1999, JT Kirkpatrick wrote:


> 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??

Perhaps as a work around you should use an integer field, which is scaled
two places to the left? That is, if you have 300.52 dollars, you keep the
number 30052 in the field. Surely you can play around with the forms you
use, so that the real field will be hidden, and get its value from a
visible field multiplied by 100.

It becomes a problem if your sums can go beyond the 2^31 limit. But if you
have 6.4, you may use int8 and double your upper limit.

The problem with the money type is that queries on it return it with a
currency mark, which I'm sure is bad for odbc.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




Re: [INTERFACES] RE: [ADMIN] float4

From
José Soares
Date:
Herouth Maoz ha scritto:

> At 23:53 +0300 on 28/06/1999, JT Kirkpatrick wrote:
>
> > 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??
>
> Perhaps as a work around you should use an integer field, which is scaled
> two places to the left? That is, if you have 300.52 dollars, you keep the
> number 30052 in the field. Surely you can play around with the forms you
> use, so that the real field will be hidden, and get its value from a
> visible field multiplied by 100.
>
> It becomes a problem if your sums can go beyond the 2^31 limit. But if you
> have 6.4, you may use int8 and double your upper limit.
>
> The problem with the money type is that queries on it return it with a
> currency mark, which I'm sure is bad for odbc.
>
> Herouth
>
> --
> Herouth Maoz, Internet developer.
> Open University of Israel - Telem project
> http://telem.openu.ac.il/~herutma

I would like to reccomend to use the DECIMAL type instead of MONEY but I see
that PSQLODBC doesn't recognize
yet this type, maybe we can ask Byron to add this new feature to PSQLODBC  ?

--
______________________________________________________________
PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc 2.7.2.3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jose'