Mailing List Archive



Back to the month index Back to the list index

Alvin Starr (alvin@iplink.net)
Thu, 10 Apr 1997 09:27:02 -0400 (EDT)


Date: 	Thu, 10 Apr 1997 09:27:02 -0400 (EDT)
From: Alvin Starr <alvin@iplink.net>
Subject: Re: [mSQL] Real rounding, precision
Message-Id: <Pine.OSF.3.91.970410090850.29178A-100000@caesar.iplink.net>

On Thu, 10 Apr 1997, Clyde Smith-Stubbs wrote:
>
> Thus spake Craig Riter (criter@riter.com):
>
> > I am trying to store the number 69.99 in a type real field. I can insert it into the table but when I do a select it displays the number as 69.98999999999999. I can use a where clause and have it match 69.99 but I am curious as to why it does not want to store this as 69.99.
>
> That's because 69.99 is not exactly representable as a 64 bit IEEE format double float.
> If you print it out to 2 decimal places, you will get 69.99 as you expect.
>
one other solution is to chose your unit size so that you do not have to
use a fractional value and then just scale down when you want to
output/print the value. 69.99 becomes 6999. ieee floating point will work
with integer values with no loss of precesion up to about 2**54

> But!
>
> > If you want to know why, I am trying to store dollar values and thought I would use the real type but I am starting to rethink that. Maybe I should have used int or char.
>
> IMHO, using floating point numbers to represent money values is a Bad Idea. I use
> integers (4 byte) in cents, which will hold values up to about $20,000,000 which
> is enough for now. If I had 20 million dollars I could afford to hire someone

You are assuming dollars(US). I am not sure of the exchange rates so may
be wildly wrong. but if the value is Paseos or Yen or Francs the
20,000,000.00 may not be enough to by a decent house.

With inflation and international business there may be real value in
64bit CPU's. This runs counter to what the folks at intel say where there
solution is to use 80bit floating point to do 64 bit integer calculations.
But then again they have a lot invested in a specific 32bit achitecture.

> to write it in Cobol. To represent larger values as integers, you can either use
> BCD strings, or a pair of integers, with some more complicated arithmetic.

gcc now supports long long, and in my Java spec long is defined as a 64
bit value. It may nice if mSQL supported a 64 bit data type.

>
> mSQL 2.0B6 has money field types, I think - not sure how they're implemented.

Alvin Starr || voice: (416)493-3325
Interlink Connectivity || fax: (416)493-7974
alvin@iplink.net ||

--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!