Topic: Formatting a calculated field on a data grid

How can I format a calculated database field on a data grid so that it shows 2 decimal places eg 99.99 rather than 99?

Re: Formatting a calculated field on a data grid

Try this:

printf('%.2lf', fieldname)
Dmitry.

Re: Formatting a calculated field on a data grid

Problem solved, many thanks.

Is it possible to right align using the printf command?

Re: Formatting a calculated field on a data grid

You can do it using a script, example:

procedure Form1_TableGrid1_OnChange (Sender: string);
begin
     Form1.TableGrid1.Columns[0].Alignment := taRightJustify; // first column
     Form1.TableGrid1.Columns[1].Alignment := taCenter; 
     Form1.TableGrid1.Columns[2].Alignment := taLeftJustify; 
end;
Dmitry.

Re: Formatting a calculated field on a data grid

How can I add the decimal places to a "sum" in the footer?

Re: Formatting a calculated field on a data grid

davidsmyth wrote:

How can I add the decimal places to a "sum" in the footer?

You can do it using script, example:

procedure Form1_TableGrid1_OnChange (Sender: string);
begin
    Form1.TableGrid1.Columns[3].Footer.Caption := FormatFloat('0.00', Form1.TableGrid1.Columns[3].Footer.FormulaValue)
end;

also you can download project with example

Post's attachments

Attachment icon Footer formatting.zip 5.58 kb, 429 downloads since 2015-09-24 

Dmitry.

Re: Formatting a calculated field on a data grid

Thanks - All working