Recent

Author Topic: [SOLVED] SQLite and 2 decimals  (Read 9673 times)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[SOLVED] SQLite and 2 decimals
« on: March 10, 2016, 09:14:14 pm »
I am using this SQL-statement to create a query/view.
Code: SQL  [Select][+][-]
  1. SELECT Wed_Meetellen, Scheidsrechter AS Referee, COUNT(Scheids_ID) AS Games, SUM(Vergoeding_Wed) AS Fee, SUM(Vergoeding_KM) AS Milage
  2. FROM qry_Temp_Uitbetalen
  3. WHERE ABS(Wed_Meetellen) = 1
  4. GROUP BY Scheidsrechter
  5. ORDER BY Scheidsrechter;  
This outlines all the numbers on the right and i have decimal numbers like 100.1
I want to have to digits after the point (like 100.10).
With the following code i can get the 2 digits decimals but it lines the column out to the left side.
Code: SQL  [Select][+][-]
  1. SELECT Wed_Meetellen, Scheidsrechter AS Referee, COUNT(Scheids_ID) AS Games,
  2. printf("%.2f",SUM(Vergoeding_Wed)) AS Fee,
  3. SUM(Vergoeding_KM) AS Milage
  4. FROM qry_Temp_Uitbetalen
  5. WHERE ABS(Wed_Meetellen) = 1
  6. GROUP BY Scheidsrechter
  7. ORDER BY Scheidsrechter;  


Question: How can i get a 2 digit decimal AND the column is outlined to the right?
« Last Edit: March 12, 2016, 07:47:25 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

balazsszekely

  • Guest
Re: SQLite and 2 decimals
« Reply #1 on: March 11, 2016, 05:05:41 am »
For each field in the query you have a DisplayFormat property + the OnGetText event. Use one of those to format the output. Even more, you have the Alignment property to change the alignment(left, center, right).

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: SQLite and 2 decimals
« Reply #2 on: March 11, 2016, 05:43:24 am »
I have the following DBGrid and its linked to the rest.
Code: Pascal  [Select][+][-]
  1.     DBGrid_Evaluaties: TDBGrid;
  2.     DS_Evaluaties: TDataSource;
  3.  
  4.     TQ_Evaluaties: TSQLQuery;
  5.  


Could you give me an example because i don't know how to address both
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

balazsszekely

  • Guest
Re: SQLite and 2 decimals
« Reply #3 on: March 11, 2016, 06:19:37 am »
I don't know how can I be more specific: https://youtu.be/n4WW5XxLsMc

PS: For formating use the DisplayFormat or the OnGetText event not both.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: SQLite and 2 decimals
« Reply #4 on: March 11, 2016, 07:21:29 am »
Yes.. now i see....
But this is all in design time.
I am making my query in runtime so i don't have the fields at design time.
This is my code.....
But then i am stuck %)
Code: Pascal  [Select][+][-]
  1.   TQ_Evaluaties.Active := False;
  2.   cSQL := 'SELECT ' +
  3.           'Wed_Meetellen, Scheidsrechter AS Referee, COUNT(Scheids_ID) AS Games, ' +
  4.           'SUM(Vergoeding_Wed) AS Fee, ' +
  5.           'PRINTF("%.2f", SUM(Vergoeding_KM)) AS Milage ' +
  6.           'FROM qry_Temp_Uitbetalen ' +
  7.           'WHERE ABS(Wed_Meetellen) = 1 ' +
  8.           'GROUP BY Scheidsrechter ' +
  9.           'ORDER BY Scheidsrechter;';
  10.   TQ_Evaluaties.DataBase := Form_Information.Connect_RefereeDB;
  11.   TQ_Evaluaties.SQL.Text := cSQL;
  12.   TQ_Evaluaties.Active := True;
  13.  
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

balazsszekely

  • Guest
Re: SQLite and 2 decimals
« Reply #5 on: March 11, 2016, 07:42:23 am »
You can also access those properties at runtime:

Code: Pascal  [Select][+][-]
  1.  
  2.   TQ_Evaluaties.Fields[I].Alignment := taLeftJustify;
  3.   Label1.Caption := Format('...', TQ_Evaluaties.FieldByName('Vergoeding_Wed').AsFloat);
  4.  
« Last Edit: March 11, 2016, 08:17:16 am by GetMem »

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: SQLite and 2 decimals
« Reply #6 on: March 11, 2016, 09:16:54 am »
It's not really created in runtime :D
Bu I know what you mean. Also in runtime you can format your decimals
Code: Pascal  [Select][+][-]
  1.   TFloatfield(TQ_Evaluaties.FieldByName('Vergoeding_Wed')).Displayformat := '####0.00';
  2.  
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: SQLite and 2 decimals
« Reply #7 on: March 12, 2016, 07:47:14 pm »
Thanx everyone
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

 

TinyPortal © 2005-2018