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
procedure TableBeforePost(DataSet: TDataSet);
begin
TableField.Value:=Int(TableField.Value*100)/100;
end;
Paolo
Daniel Lodeiro ha scritto:
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
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)
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
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
>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
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)
--