Subject Re: [IBO] Anyone using numerics with more than 4 decimal places?
Author Geoff Worboys
What I started to implement was standard decimal numbers as per
http://speleotrove.com/decimal/

I first started using such types in a C++ development where we
stored the values in the database as text fields - because that
allows you to edit the values directly using existing tools.
As part of that work I have the code for collating such fields
to order and index them correctly in Firebird.

I used the 32bit C/C++ compiler from C++Builder v6 to build obj
files (so it's definitely 32bit only at this time) from one of
the packages from that link above. To be able to link this into
a Delphi project I also had to create a unit to give me access
to some functions from msvcrt.dll.

Then, in Delphi, I created a TDecimalEnh class to encapsulate
the decQuad structure as described in the above link - a 128bit
value that emulates an IEEE-754 "decDouble" type, which is a
decimal type of 34 digits decimal precision. (That is: numbers
that behave like you were taught in school, not the mucked up
versions you get with binary floating point.)

I also created test code to prove that the Delphi code passes
all the relevant tests provided in the link above.

I also created a generalised formatting unit so that I could
input and output formatted text versions of the numbers.

I got this much working under Delphi XE2 (I think it was)
before I got pulled away to other priorities and haven't been
back since.

What all this means is that I have a fully functional 34-digit
decimal number type for Delphi, but I never got to the point of
implementing a data-aware variation for IBO. It was my
intention to use this as the basis for a major upgrade to one
of my existing projects.

Such types are necessarily slower than binary floating point -
lots is done in code that would normally be done in the
processor, but it seems to perform adequately.

I have no particular intention of using Delphi's TFMTBCD type,
and I don't use TDataset ... so this probably this doesn't help
you very much. Even though I have done a lot, there is still
a lot that would have to be done to get this into a production
system - eg: integration with IBO AND with your reporting tool.

So that is my still incomplete approach to solving the problem,
and it's a big problem. 15 and 18 digit precision just doesn't
cut it any more.

--
Geoff Worboys
Telesis Computing Pty Ltd


Carlos H. Cantu wrote:
> I faced the situation where I need to have numerics defined
> with more than 4 decimal places. The problem is that such
> fields are handled by IBO as Float fields, so is subject to
> the well known precision problems associated to the float
> format (what you store is not always exactly what you get
> back).

> Delphi has a type called TFMTBCD that is supposed to deal
> with numerics with more than 4 decimal places as BCD values,
> to avoid the problems of the float format. The problem is
> that IBO is not aware of TFMTBCD.

> Has anyone here able to find out a good solution for this
> problem?

> PS: I mostly use TDataset IBO derived components with
> persistent fields.