Formatting decimal values
Hi ho!
I'm having trouble getting decimal numbers to format correctly in the grid. I've tried changing the default formats of the cube without success, and can't figure it out.
I'm using a Firebird database. Placing a DBGrid on the form, using the same datasource, everything is formatted as per the query (for example 2 decimals), but in the fcGrid it cuts of decimals if they are zeros.
How would I get everything - all decimal numbers - to have exactly 2 decimals and a comma as the decimal separator?
TIA!
I'm having trouble getting decimal numbers to format correctly in the grid. I've tried changing the default formats of the cube without success, and can't figure it out.
I'm using a Firebird database. Placing a DBGrid on the form, using the same datasource, everything is formatted as per the query (for example 2 decimals), but in the fcGrid it cuts of decimals if they are zeros.
How would I get everything - all decimal numbers - to have exactly 2 decimals and a comma as the decimal separator?
TIA!
Comments
Use format string:
%2.2f
or
%2.2n
Oleg.
I have tried both of those (in the fcCube.DefaultFormat.FloatFormat), but nothing happens. Even if I try something else, it doesn't change the formatting at all. I've tried casting the numeric field to DECIMAL(9,2) or NUMERIC(9,2), and it affects the display in the DBGrid but not the fcGrid which just cuts off the decimals.
FYI: in FastReports that same formatting works ok, I've used it for a few years already.
fcCube.DefaultFormat is used for creating fields when the data are loaded from a database.
When the cube is opened fcCube.DefaultFormat is not used.
If You load cube from file or stream, is used saved format.
You can change format in slice fields or measures directly.
Oleg.
fcSlice1.AddFieldTo('rowsum', 'Row sum', rf_CapFacts, af_Sum);
How do I set the displayformat for it to be '%2.2f' ?
TIA!
var AIndex: integer;
begin
...
AIndex := fcSlice1.AddFieldTo('rowsum', 'Row sum', rf_CapFacts, af_Sum);
fcSlice1.BeginUpdate;
fcSlice1.CapFactsFieldsAbs[AIndex].DisplayFormat.Kind := fkNumeric;
fcSlice1.CapFactsFieldsAbs[AIndex].DisplayFormat.FormatStr := '%2.2f';
fcSlice1.EndUpdate;
And see demo "FastCube examples".
Oleg.
...and now that you mentioned, I found the formatting stuff in the examples. Thanks for that too!
thanks for this.have the same question.