Number Formatting Via Dynamic Cellstyle

(5 posts) (2 voices)

Tags:

  1. thewah, Member

    I'm trying for properly format some numbers using the printf style arguments. I am trying to do so via dyanamic styles. I can select the style and it works for color/background/etc formatting, but I can't get it to properly add special characters ($,%).

    If I don't do dynamic styling, printf errors out (I have a case statement that returns "N/A" for a number of fields, but the normal styling errors out during printf on character fields)

  2. myDBR Team, Key Master

    What have you tried?

    --
    myDBR Team

  3. thewah, Member

    Using this for formatting...

    select 'dbr.cellstyle','Pay Per Funded Deal','moneystyle';
    select 'dbr.cellstyle','Payroll Adjustment','moneystyle';
    select 'dbr.cellstyle','Personal Funding %','percentstyle';

    And this to set the style...

    select
    date_format(p.start_date,'%Y/%m') as 'Month',
    [many field removed]
    ,if(month(now()) = month(p.start_date) or month(now())-1 = month(p.start_date),'notfoundstyle',if(special_number>=0,'color:green;$%.2f;','color:red;$%.2f;')) as '[moneystyle]'
    ,if(month(now()) = month(p.start_date) or month(now())-1 = month(p.start_date),'notfoundstyle','%.2f%') as '[percentstyle]'
    from
    ...

  4. myDBR Team, Key Master

    The cellstyle column should only contain a CSS style. You can set the prefix and number of decimals with dbr.colstyle.

    --
    myDBR Team

  5. thewah, Member

    I was originally using colstyle, but it would kick out a printf error when trying to apply formatting to the "N/A" returned by some of the snipped queries (for the two most recent months, it doesn't return a numeric value, but a string).

    I was able to get there by just rounding the values to the proper precision and concatenating the special characters, so it eventually worked out.


Reply

You must log in to post.