Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

About decimal place precision

58 views
Skip to first unread message

Daniel Lodeiro

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
Hi All

How Can I make my Database application in Delphi and work with two decimal
places of precision?
I don't need more precision besides I want to be sure that if I store 12.34
in a field when read this field not read 12.339999999999999, this thing
apear to be simple but with the float representation of number in a Paradox
table I don't know which are the solution. (maybe convert all using BCD).

Please the idea is simple no more two decimal places on any number.
When I worked with DBASE the field has the decimal places that you defined
and the representation was exactly what you store what happening with
Paradox?

Any help please, like you see in a database application the round problems
are bigs problems.
Thanks in advanced.
Daniel


Paolo Sparvieri

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
To store a float with not more than 2 precision digits,
you could write something like this:

procedure TableBeforePost(DataSet: TDataSet);
begin
TableField.Value:=Int(TableField.Value*100)/100;
end;


Paolo

Daniel Lodeiro ha scritto:

Sundial Services

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
Yes, Daniel, under these requirements you should use BCD
representation. You need absolute control over the precision. The
SysTools library has a good BCD system.

You might also be able to get away with scaled integers; that is,
"12.34" is stored and processed as the integer "1,234." Every value is
defined to be an integer that is 100 times larger than the equivalent
floating-point. (Many accounting systems use "10,000 times larger,"
creating a 4-digit fixed mantissa which seems to be somewhat of an
industry-standard. The MS-Access "Currency" type uses this approach,
for instance.

What you cannot do, obviously, is to use floating-point because the
handling of values won't be what you need.

*N*O*T*E* that even though Paradox defines a BCD data-type, Paradox
stores the values as floating-point! You can override this behavior
with BDE calls.


>Daniel Lodeiro wrote:
>
> How Can I make my Database application in Delphi and work with two decimal
> places of precision?
> I don't need more precision besides I want to be sure that if I store 12.34
> in a field when read this field not read 12.339999999999999, this thing
> apear to be simple but with the float representation of number in a Paradox
> table I don't know which are the solution. (maybe convert all using BCD).
>
> Please the idea is simple no more two decimal places on any number.
> When I worked with DBASE the field has the decimal places that you defined
> and the representation was exactly what you store what happening with
> Paradox?
>
> Any help please, like you see in a database application the round problems
> are bigs problems.

------------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:in...@sundialservices.com (PGP public key available.)
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R): "Click click, it's fixed!" {tm}
> http://www.sundialservices.com/products/chimneysweep

Bill Todd (TeamB)

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
There is no perfect solution with Paradox tables since the only format they
provide for storing decimal fractions is floating point notation and most
decimal fractions cannot be represented exactly in binary floating point
notation. The best you can do is to:

1) Use Currency type variables for all calculations and
2) Round all values when you retrieve them from the database with
Round(Table1.FieldByName('SomeField').AsFloat * 100) / 100;

--
Bill

Bill Todd (TeamB)
(TeamB cannot respond to questions received via email)

John Herbster

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
"Bill Todd (TeamB)" <bi...@dbginc.com> wrote
> ... with Paradox tables since the only format they provide
> for storing decimal fractions is floating point notation ...

Bill, What about Paradox BCD fields with the number of digits after
the decimal parameter? Are they really stored as floating binary
point, too? Regards, John H

Brian Bushay TeamB

unread,
Apr 10, 2000, 3:00:00 AM4/10/00
to

>How Can I make my Database application in Delphi and work with two decimal
>places of precision?
>I don't need more precision besides I want to be sure that if I store 12.34
>in a field when read this field not read 12.339999999999999, this thing
>apear to be simple but with the float representation of number in a Paradox
>table I don't know which are the solution. (maybe convert all using BCD).

For Paradox tables BCD field type is your best option. There is no option to
set precision on Number or Currency fields.


--
Brian Bushay (TeamB)
Bbu...@NMPLS.com

Jan Sprengers

unread,
Apr 10, 2000, 3:00:00 AM4/10/00
to
On Sun, 9 Apr 2000 14:53:49 -0700, "Bill Todd \(TeamB\)"
<bi...@dbginc.com> wrote:

>2) Round all values when you retrieve them from the database with
>Round(Table1.FieldByName('SomeField').AsFloat * 100) / 100;

Bill,

If you always retrieve the field values into a Currency variable, it
shouldn't even be necessary to round because Delphi would
automatically round to 4 decimal places for you then.

Here is an example:

procedure TForm1.Button1Click(Sender: TObject);
var
C1, C2: Currency;
F: Extended;
begin
C1 := 0.0010;
F := C1;
F := F - 0.000045555;
C2 := F;
if C1 = C2 then
ShowMessage('Equal');
end;

Jan


Bill Todd (TeamB)

unread,
Apr 10, 2000, 3:00:00 AM4/10/00
to
You are right of course. The only exception is if you want to round the
value in the currency field to two decimal places before doing calculations.

Daniel Lodeiro

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
How Visual Basic make this work of presicion?
Best Regards
Daniel

Brian Bushay TeamB

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to

>How Visual Basic make this work of presicion?
I have no knowledge of how visual basic treats Paradox fields

Sundial Services

unread,
Apr 13, 2000, 3:00:00 AM4/13/00
to
The best analogy I ever heard about decimal precision is that "numbers
are like little piles of dirt in the sand... every time you move them
you pick up a little dirt and lose a little bit of sand." The
floating-point numeric type stores the mantissa (the fractional part) in
a float-binary (base-2) representation, and the exponent as a separate,
integer, representation... and never the twain shall meet.

Accountants, ahem..., don't always like that. :->

If numeric precision ["significant digits"] matters to you "in an
accounting sort of way..." then the traditional float-binary
representation =isn't= appropriate for your application because
float-binary is geared toward "the engineering sort of way..." If you
absolutely must care, as accountants absolutely must care, about the
fourth digit to the right of the decimal point, then float-decimal
("extended," "real") is NOT for you.

>Bill Todd (TeamB) wrote:
>
> There is no perfect solution with Paradox tables since the only format they
> provide for storing decimal fractions is floating point notation and most
> decimal fractions cannot be represented exactly in binary floating point
> notation. The best you can do is to:
>
> 1) Use Currency type variables for all calculations and

> 2) Round all values when you retrieve them from the database with
> Round(Table1.FieldByName('SomeField').AsFloat * 100) / 100;
>

> --
> Bill
>
> Bill Todd (TeamB)
> (TeamB cannot respond to questions received via email)

--

0 new messages