Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Negative Number Formatting

  1. #1
    Join Date
    Aug 2007
    Posts
    15

    Default Negative Number Formatting

    Hi,
    I would like to be able to format my negative numbers differently than my positive ones in a common accounting manner:
    a) surrounded by parentheses, e.g., (1,222.03), where positive have no parens
    b) in red, where positive in black

    Anyone know how I can specify this, if its possible?
    Last edited by panos; 12-31-2007 at 02:59 PM.

  2. #2

    Default

    Hi can you be more specific about where you would like to see this accomplished. The methods will vary depending on whether you want to see it in drillable reports, ad-hoc reports or in pre-defined reports.

    Zach
    BizCubed Pty Ltd
    Australian Pentaho Partner

  3. #3
    Join Date
    Aug 2007
    Posts
    15

    Default

    I'm talking about a simple Label in an ItemBand created using a LabelElementFactory in the API. Does that help?

  4. #4
    Join Date
    Jan 2006
    Posts
    460

    Default

    Would using a simple style expression work for you?

    http://wiki.pentaho.org/display/Repo...bFormulaSyntax

    -Mike

  5. #5
    Join Date
    Aug 2007
    Posts
    15

    Default

    I don't see how that would work. Don't see any formatting posibilities (e.g., foreground color)?

  6. #6
    Join Date
    Aug 2007
    Posts
    15

    Default

    I got it.

    Wrap the original TableModel in a wrapper TableModel that has two columns for each column in the original TableModel.

    wrapperTM.getColumnCount() == origTM.getColumnCount()*2

    wrapperTM.getColumnName( col ) returns origTM.getColumnName( col/2 ) + (col%2 == 0 ? ".pos" : ".neg" )

    wrapperTM.getValueAt() should return the value in the ".pos" column if positive and in the ".neg" column if negative, so:
    wrapperTM.getValueAt( int row, int col ) returns
    Double d = (Double)origTM.getValueAt( row, col/2);
    if( col %2 == 0 )
    return d >= 0 ? d : null;
    else
    return d < 0 ? d : null;

    Then in setting up the ItemBand, you overlap two labels for each column in the original TableModel (don't forget to add the ".pos" and the ".neg"), setting up the differing formatting as you wish for positive or negative values -- in my case, black for positive, red for negative.

    QED.

  7. #7

    Default

    Hi,

    you can set formula on style properties of elements as in this exemple:
    Code:
    <label x="0" y="3" width="200" height="15">Number of Elements<style-expression
            style-key="visible" formula="report:TRUE()"></style-expression></label>
    May the Moo force be with you,
    Said Mimil

    A student of JFree & Pentaho Academies,
    Cedric Pronzato

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.