Number format a decimal in Birt reports

I don't believe this can work from the onFetch script, this kind of script should be put in "onRender" event of a data element. Furthermore, the formatter returns the result so it should be:

this.setDisplayValue(df.format(row["invoicedquantity"]));

But i think it would be easier to create a computed column as datatype "String" in the dataset, with expression:

if(row["unittype"]=="Nos"){
  Formatter.format(row["invoicedquantity"],"#,###.## Kg");
}else{
  Formatter.format(row["invoicedquantity"],"#,### Kg");
}

EDIT: After a deeper look at this, i found a more appropriate way, by changing "numberformat" property. In onRender or onCreate script of the data element (which should be a number datatype), we can do something like:

if(row["unittype"]=="Nos"){
  this.getStyle().numberFormat="#,###.## Kg";
}else{
  this.getStyle().numberFormat="#,### Kg";
}

This is a better approach because the data element has still a numeric datatype, so that if the report is exported in excel it will be recognized by excel as a number.