Formatting decimal values

edited 11:57AM in FastCube
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!

Comments

  • edited 11:57AM
    Hi.

    Use format string:
    %2.2f
    or
    %2.2n

    Oleg.
  • edited 11:57AM
    Hiya,


    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.
  • edited 11:57AM
    Hi.

    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.
  • edited 11:57AM
    Ok - but could you give me an example, please (I'm a bit thick today <g>). For example if I add this field in code:

    fcSlice1.AddFieldTo('rowsum', 'Row sum', rf_CapFacts, af_Sum);

    How do I set the displayformat for it to be '%2.2f' ?


    TIA!
  • edited 11:57AM
    Hi.

    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.
  • edited June 2010
    Works like a champ, thank you !

    ...and now that you mentioned, I found the formatting stuff in the examples. Thanks for that too!
  • jasonflord25jasonflord25 California
    edited 11:57AM
    wrote: »
    Hi.

    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.


    thanks for this.have the same question.

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.