Another question about Floats

sergio7

Member²
Hi,

i have a field ('MYFIELD') defined as number(14)
This number is mapped as TFloatField.

I have a procedure like this :

var
d: Double;
begin
d:= 100;
MyQuery['MYFIELD'].AsFloat := d;
MyQuery.Post;
// reloads the same record
MyQuery.Open;
if MyQuery['MYFIELD'].AsFloat = d then showmessage('ok');
...
...
Can i assume that MyQuery['MYFIELD'].AsFloat =d allways returns true ?
Can i use a number(14) as key field for a table ?

TIA

Sergio Sette
 
1. Can i assume that MyQuery['MYFIELD'].AsFloat =d allways returns true ?

Only if MyQuery return 1 row or you update 1st record of result set;

2. Can i use a number(14) as key field for a table ?

Of course, YES, if value for field is unique for each record
 
Originally posted by Vents Lauva:

Only if MyQuery return 1 row or you update 1st record of result set;

2. Can i use a number(14) as key field for a table ?

Of course, YES, if value for field is unique for each record

Ok, my table in this case contains only 1 record. The problem is that oracle stores the value as number(14) that is not a float and delphi treat this as float. Compare floating point is not so safe.

Regards

sergio sette
 
I'd suggest that you test this with a test table and some data.

For example:

In SQL*Plus:

select * from x;

90000000000000
90000000000001
90000000000002
90000000000003
90000000000004
90000000000005
-90000000000005
-90000000000004
-90000000000003
-90000000000002
-90000000000001
-90000000000000

now in Delphi:

with OracleQuery1 do begin
Execute;
while not(EOF) do begin
Memo1.Lines.Add(Format('%14.0f', [FieldAsFloat(0)]));
Next;
end;
end;

90000000000000
90000000000001
90000000000002
90000000000003
90000000000004
90000000000005
-90000000000005
-90000000000004
-90000000000003
-90000000000002
-90000000000001
-90000000000000

Looks like float (double) is good enough for number(14).
 
Originally posted by jpickup:
I'd suggest that you test this with a test table and some data.

Looks like float (double) is good enough for number(14).


Tanks,
I have found that this is true for number(n) with n
 
Back
Top