Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My Query rounds off numbers, but I 1

Status
Not open for further replies.

NewToProgramming

Technical User
Jun 24, 2003
31
US
My Query rounds off numbers, but I don't want it to.
How do you stop that from happening?
Here is my code:

Query := TQuery.Create( nil );
I := 1;
R := 0;
Query.DataBaseName := Table1.DataBaseName;
Query.SQL.Add( 'SELECT (field) as whatever from db.Db' );
try
Query.Open;
Query.First;
while not Query.Eof and (i<=10) do
begin
R := R + Query.FieldByName('Whatever').AsInteger ;
Query.Next;
Inc(i);
Form3.Edit1.Text := FormatFloat(FormatSpec, R div 10);
end;
finally
Query.Free;
end;
Result := True;
end;
 
hi

It'll be the DIV command, that returns an integer(the left part only of the decimal result, and Mod returns the remainder only as an integer).

Try

Form3.Edit1.Text := FormatFloat(FormatSpec, R/10);

lou


 
..Also, is the field you're retrieving from the database an integer ? If not, you'll need AsFloat.


 
The Field is listed in delphi as
Differential : TFloatField; Is that right? when I created the field using Database Desktop I selected the number type.

I changed the Div to / and it still rounds off.
If Integer is whole numbers only, then it must be the line that says:
R := R + Query.FieldByName('Whatever').AsInteger ;
But, I tried to change AsInteger to AsFloat, but that gave an error saying:
incompatible types: Integer and Real.
Ok, where is it getting the Integer type from?
Mark
 
It is always the stupidest error.
Thank you,
Totally forgot to set my variable to a float. Was too busy looking for my screw up in the code itself.
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top