tags:

views:

300

answers:

2

Hi fellow programmer

I want to ask how to add a computed column in BIRT that compute a number to its word representation? (ex. 100 to "one hundred") So in my data set I can have a column that holds the string

I'm new at BIRT hopefully there's a pointer or two for me

+1  A: 

I am aware this is quite an old post, but if you are still interested, this is how I'd go about doing it:

Add a script or jar that containing a function / method that would convert a number to a textual representation. To do this, for example, create a server-side-utilities.js file and in the 'Resource Explorer' tab add the resource. Then, in the 'properties editor' for the report itself, click the 'resources' tab and add that JS file.

Then edit the JS file to include a function that converts a number to text and save it. Then in your dataset dialog add a computed column, name it, set data type to string, and set the expression to invoke the defined function, passing to the function the value of the relevant column, e.g. convertNumberToText(row["NUMERIC_COL"]).

A partial implementation of convertNumberToText() might be:

function convertNumberToText(number)
{
  var text;

  switch (number)
  {
    case 1:
    {
      text = "One";
      break;
    }
    default: text = "Unsupported number";
  }

  return text;
}
Ed
A: 

Actually, I'm going to offer another solution even though this question has an accepted answer.

Create a conversion table in the database itself along the lines of:

number  as_one       as_first
------  -----------  ------------
     1  one          first
     2  two          second
    99  ninety-nine  ninety-ninth

and just use a query (or sub-query or implicit/explicit join) to retrieve the textual value of the number you're interested in.

This greatly simplifies the code out on the client at the cost of minimal storage and a bit of table set-up.

paxdiablo