How To Get a Float Value out of Query ? lazarus / 16-Databases ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 12:39 Hello Guys, So this is my Code : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i VText3.Caption := Trim((Round((dbKFilter.FieldByName('MaxEff').AsFloat - (dbKFilter.FieldByName('EfP1').AsFloat + power(VLuft, dbKFilter.FieldByName('EfP2').AsFloat) * dbKFilter.FieldByName('EfP3').AsFloat) * dbKFilter.FieldByName('EfP4').AsFloat))).toString);      In the Attacchments is A Picture Of The Database afther i Selected The Row (Tested it this work correctly) But i don't get my Float VAlues out of the Db The Field EfP2 gets 0 The Field EfP3 gets 10 why is it rounding those numbers ? i used .AsFloat and .Text.ToSingle The Fields in the DB(SQLite) are Type Float. Am i missing Something ? ---------------------------------------------------------------------- balazsszekely · 2020-12-17 12:52 QuoteBut i don't get my Float VAlues out of the Db The Field EfP2 gets 0 The Field EfP3 gets 10Are you sure?  In my opinion there are too many calculation in a single line. Perhaps you could try something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  MaxEff, EfP1: Double;begin  //...  MaxEff := dbKFilter.FieldByName('MaxEff').AsFloat;  EfP1 := dbKFilter.FieldByName('EfP1').AsFloat;  ShowMessage(FloatToStrF(MaxEff, ffFixed, 8, 10) + sLineBreak +  FloatToStrF(EfP1, ffFixed, 8, 10));end;  What are the values of MaxEff and Efp1 now? ---------------------------------------------------------------------- rvk · 2020-12-17 13:21 Quote from: Weitentaaal on December 17, 2020, 01:39:16 pmwhy is it rounding those numbers ? i used .AsFloat and .Text.ToSingle Then why do you use round() around those asFoats ??? https://www.freepascal.org/docs-html/rtl/system/round.html QuoteRound floating point value to nearest integer number. ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 13:31 @rvK i wanted to Round the Result thats Fine. MaxEff = 94,00000000 EfP1 = 0,00000000 i used EfP2 (Value 0.8 ) and Recieved 0,000000 i was looking again but i did not see where i could do a rounding mistake. it must be a mistake when i try to get the Value through the .AsFloat Function ---------------------------------------------------------------------- rvk · 2020-12-17 13:40 Then show the SQL of dbKFilter. And show the individual values of dbKFilter.FieldByName('MaxEff').AsFloat dbKFilter.FieldByName('EfP1').AsFloat dbKFilter.FieldByName('EfP2').AsFloat dbKFilter.FieldByName('EfP3').AsFloat dbKFilter.FieldByName('EfP4').AsFloat Show the code how you retrieved them and showed them on your screen. Also, what value has dbKFilter.FieldByName('EfP2').DataType ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:04 Code : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    dbExecute(dbKFilter, 'SELECT * FROM WABE WHERE TRIM(BESCHREIBUNG) = '+ Afz + Trim(Combo1.Text) + Afz);      ShowMessage(dbKFilter.SQL.Text + sLineBreak + sLineBreak + sLineBreak + 'MaxEff Value : (.AsFloat)' +FloatToStrF(dbKFilter.FieldByName('MaxEff').AsFloat, ffFixed, 8, 10) + sLineBreak +   'EfP2 Value : (.text.ToSingle)' +FloatToStrF(dbKFilter.FieldByName('EfP2').text.ToSingle, ffFixed, 8, 10));     VText3.Caption := Trim((Round((dbKFilter.FieldByName('MaxEff').AsFloat - (dbKFilter.FieldByName('EfP1').AsFloat + power(VLuft, dbKFilter.FieldByName('EfP2').AsFloat) * dbKFilter.FieldByName('EfP3').AsFloat) * dbKFilter.FieldByName('EfP4').AsFloat))).toString);       //dbExecute --> (Did Always work i think its not the Problem) Procedure dbExecute(var Recordset: TSQLQuery; Query: String); //TSQLQuery entspricht VB6 Recordset (fast)Begin  Recordset.Clear;  //Recordset := TSQLQuery.Create(nil);  Recordset.UsePrimaryKeyAsKey := False;  Recordset.DataBase := sqlConnWSET;  Recordset.PacketRecords := -1;  Recordset.SQL.Text := Query;  Recordset.Open;End;    All the Rsults i Get are in attatchement And Combo1.Text = KA100 ---------------------------------------------------------------------- rvk · 2020-12-17 14:10 Why are you using bKFilter.FieldByName('EfP2').text.ToSingle ?? Why not just bKFilter.FieldByName('EfP2').asFloat? (in the Showmessage) ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:14 Was just Looking if there is Any Problem in this (i never overwrote .text or.asfloat, so it must have the same Result or am i wrong ?) Edit: Re-Wrote it to .AsFloat (Still the Same result) And Thanks For ur Help So Far ---------------------------------------------------------------------- rvk · 2020-12-17 14:18 Not sure. Just do a Showmessage with asFloat and see if it comes back with 0,8 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ShowMessage(dbKFilter.SQL.Text + sLineBreak + sLineBreak + sLineBreak +   'MaxEff Value : (.AsFloat)' + FloatToStrF(dbKFilter.FieldByName('MaxEff').AsFloat, ffFixed, 8, 10) + sLineBreak +  'EfP2 Value : (.AsFloat)' + FloatToStrF(dbKFilter.FieldByName('EfP2').asFloat, ffFixed, 8, 10)); ---------------------------------------------------------------------- rvk · 2020-12-17 14:20 I already see the problem. EfP2 is a text field !! You can see that from the fact there is a , as decimal character. For MaxEff you see a . as decimal character. So you probably saved the value in the database as HARD 0,8 (with a ,) while the DB value should have been 0.8. SQLite isn't really strong typed and you can put a string value in a decimal field without a problem. (well... except that you got a problem when reading it out as a float, which it isn't_ ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:25 How ??? Look at the Picture (attatch.) It has to be Float Already checked that twice ---------------------------------------------------------------------- rvk · 2020-12-17 14:27 Quote from: Weitentaaal on December 17, 2020, 03:25:17 pmHow ??? Look at the Picture (attatch.) It has to be Float Already checked that twice NO... Look again. Like I said... you can put a STRING into a DECIMAL or FLOAT field in SQLite. And that's what you did. If I look at your values I see 94.0 (see the .  !!) 0,800000 etc (see the , ) A , is different from a . And if you insert 0,8 (with a ,) SQLite just sees it as a string. So all those fields with , are actually strings. Despite the field definition (which SQLite doesn't really care about). ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:28 Now i See this too but why is the half of the Fields a Text Field while the other is not ?? Like Look at this Mess ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:29 But Thanks a Lot @rvk ---------------------------------------------------------------------- rvk · 2020-12-17 14:30 Yes. So all those fields with , are really strings. I don't know how you filled those but they are not FLOATs. BTW, some are (the ones with .). So for those you would get correct results. ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:33 But why do i keep getting the Wrong Result even if i use .AsString ? It's a String Field right ? So why do i not get the whole String ? And i Still Remember i Got sometimes Exceptions where it Said Syntax error near "," so i had to replace "," with "." . So it couldn't even insert those Values. So confused right now ---------------------------------------------------------------------- rvk · 2020-12-17 14:37 Quote from: Weitentaaal on December 17, 2020, 03:33:56 pmBut why do i keep getting the Wrong Result even if i use .AsString ? It's a String Field right ? So why do i not get the whole String ? What does this show? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Showmessage(dbKFilter.FieldByName('EfP2').asString); It could be that FPC does consider the field a Float. But when reading the data it gets 0,8 and 0,8 isn't a float so it can't put any value in the dbKFilter.FieldByName('EfP2'). If you edit the database with that other databasemanager and make the fieldvalue 0.8 you'll see it works out fine. ---------------------------------------------------------------------- Weitentaaal · 2020-12-17 14:48 You were right (not that I doubted it ) worked ! Thanks @rvk have a nice Day !