formating numeric

edited April 2008 in FastReport 4.0
I'd made some totals in group header, but the result show 12345.1234, I just need 12345.12, I'd tried to use format() function, but it prompt error. How to use the function?
Var List1,List2: TStringList;
    i: Integer;

procedure frxReport1OnStartReport(Sender: TfrxComponent);
begin
  List1:=TStringList.Create;
  List2:=TStringList.Create;                                                            
end;

procedure Page1OnBeforePrint(Sender: TfrxComponent);
begin
  i:=0;          
end;

procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
begin
  if Engine.FinalPass then
  begin
    Memo34.Text := Format('%2.2n',[List1[i]]);  //won't work                         
    Memo36.Text := List2[i];                    //work, but without format                                                                                                                 
  end;            
end;
    
procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
begin
  if not Engine.FinalPass then
  begin              
   List1.Add(SUM(<Query1."QTY">,MasterData1));
   List2.Add(SUM(<Query1."AMOUNT">,MasterData1)); 
  end;
  Inc(i);                  
end;
  
procedure frxReport1OnStopReport(Sender: TfrxComponent);
begin
  List1.Free;
  List2.Free;                          
end;

begin
                      
end.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 6:48PM
    1 in any expression within a memo you are only allowed 1 set of [] as they are expression delimiters.
    but why go to all that trouble just set the display format property of the memo at design time.
    select the memo rtclck select display format.
  • edited 6:48PM
    memo34,memo36 are the field to show result of sum in group header, they are set value in final pass. Actually, I'd set the memo format by rtclck too, but it seems not work.
  • gordkgordk St.Catherines On. Canada.
    edited 6:48PM
    sorry i should have read a little closer.
    the display format property wont work as you are working with the final output string.
    i see you incrementing the index in the group footer but i dont see the index(i) being reset anywhere
    so you are probably on an empty value in the final pass, also dont forget that a tstringlist is a 0 based array of tstrings, so the first item added has an index value of 0.
    you might also want to look at the main demo.
    under dialogs and script "totals in group header" report, to see how we handled it as well as the user manual.
  • edited 6:48PM
    Thank you for your reply, I refered the manual and demo to make this report. 'cause there is not only one field to sum total, I create two TStringList to set value, and it works out , but just only the display format has problem. I found the demo file also set format in this way, but I don't know why my code doesn't work. I'd post whole code on my first post. Could you have a look if convenient?
  • gordkgordk St.Catherines On. Canada.
    edited 6:48PM
    here is some sample code for the demo report 45.fr3
    using a tstringlist.
    Var List1,List2: TStringList;
    idx: Integer;
    procedure Band7OnBeforePrint(Sender: TfrxComponent);
    begin
    // Set(<Sales."Company">, Sum(<Sales."Qty">*<Sales."List Price">));

    if not engine.finalpass then
    begin
    // format the value when adding the the string to the list.
    list1.add(Format('%2.2m',[Sum(<Sales."Qty">*<Sales."List Price">,band6)]));
    end;

    end;

    procedure Memo4OnBeforePrint(Sender: TfrxComponent);
    begin
    if Engine.FinalPass then
    begin
    // Memo4.Text := 'Sum: ' + Format('%2.2m',[Get(<Sales."Company">)]);

    memo4.text:=List1[idx];
    inc(idx);
    end;
    end;

    begin
    List1:=TStringList.Create;
    idx := 0;
    end.

  • edited 6:48PM
    Thank you so much. The issue was solved.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.