Decimal number format in Birt reports

I have a table that gives me the values ​​in Nos and Decimal (weight-kg) For example, 10.455 kg (this is 10 kg and 455 g) and nos. as in 10 but.

Now all these values ​​are taken from the column (Decimal (10,3) -mysql) in the table and based on the unittype column I have to decide whether to have 3 decimal or zero decimal places in the BIRT report.

I know that with scripts the values ​​can be changed .. but I can not use scripts.

I am writing this on onFetch

if(row["unittype"]=="Nos") var df = new Packages.java.text.DecimalFormat("#,###.##"); else var df = new Packages.java.text.DecimalFormat("#,###"); df.format(row["invoicedquantity"]); this.setDisplayValue(df); 

I can not get the values

+6
source share
1 answer

I do not believe that this can work from an onFetch script, this kind of script should be placed in the onRender event of the data element. In addition, formatter returns a result, so it should be:

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

But I think it would be easier to create a calculated column as a data type of "String" in a dataset with an expression:

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

EDIT: After taking a deeper look at this, I found a more suitable way by changing the "numberformat" property. In the onRender or onCreate script of the data element (which should be of type number ), 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 item still has a numeric data type, so if the report is exported to excel, it will be recognized as excel as a number.

+7
source

All Articles