简体   繁体   English

Birt 报告中的数字格式为小数

[英]Number format a decimal in Birt reports

I have a table which gives me values in Nos. and Decimal (weight-kg) Eg10.455 Kg ( that is 10 Kg and 455 gms) and nos.我有一张表,它给出了编号和十进制(重量-公斤)的值,例如 10.455 公斤(即 10 公斤和 455 克)和编号。 as in 10 Nos.如10号。

Now all these values come from a column (Decimal (10,3)-mysql) in table and based on the unittype column I have to decide whether to have 3 decimal or zero decimal in the BIRT report.现在所有这些值都来自表中的一列 (Decimal (10,3)-mysql) 并且基于 unittype 列我必须决定在 BIRT 报告中是有 3 位小数还是 0 位小数。

I know that through scripting the values can be modified.. but I am unable to utilise the scripting.我知道通过脚本可以修改值..但我无法使用脚本。

I am writing this on onFetch我在 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 am unable to get the values我无法获取值

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.我不相信这可以从 onFetch 脚本中工作,这种脚本应该放在数据元素的“onRender”事件中。 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.编辑:在深入研究之后,我找到了一种更合适的方法,通过更改“numberformat”属性。 In onRender or onCreate script of the data element (which should be a number datatype), we can do something like:在数据元素(应该是数字数据类型)的 onRender 或 onCreate 脚本中,我们可以执行以下操作:

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.这是一种更好的方法,因为数据元素仍然具有数字数据类型,因此如果报表以 excel 导出,excel 会将其识别为数字。

Easiest way is use Number formatting with Fixed decimals,最简单的方法是使用带有固定小数的数字格式,

Select the field Go to: Property Editor -> Number formatting选择字段转到:属性编辑器 -> 数字格式

Select Currency and change accordingly.选择货币并进行相应更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM